Skip to content

Commit e04ec56

Browse files
authored
Merge pull request #66 from mindsdb/staging
Release 1.0.6
2 parents e3f623e + d004f88 commit e04ec56

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

mindsdb_sdk/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = 'mindsdb_sdk'
22
__package_name__ = 'mindsdb_sdk'
3-
__version__ = '1.0.5'
3+
__version__ = '1.0.6'
44
__description__ = "MindsDB Python SDK, provides an SDK to use a remote mindsdb instance"
55
__email__ = "jorge@mindsdb.com"
66
__author__ = 'MindsDB Inc'

mindsdb_sdk/model.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def predict(self, data: Union[pd.DataFrame, Query, dict], params: dict = None) -
8888
model_identifier.alias = Identifier('m')
8989

9090
ast_query.parentheses = True
91-
ast_query = Select(
91+
ast_query.alias = Identifier('t')
92+
upper_query = Select(
9293
targets=[Identifier(parts=['m', Star()])],
9394
from_table=Join(
9495
join_type='join',
@@ -97,9 +98,9 @@ def predict(self, data: Union[pd.DataFrame, Query, dict], params: dict = None) -
9798
)
9899
)
99100
if params is not None:
100-
ast_query.using = params
101+
upper_query.using = params
101102
# execute in query's database
102-
return self.project.api.sql_query(ast_query.to_string(), database=data.database)
103+
return self.project.api.sql_query(upper_query.to_string(), database=data.database)
103104

104105
elif isinstance(data, dict):
105106
data = pd.DataFrame([data])

mindsdb_sdk/project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def drop_view(self, name: str):
298298
:param name: name of the view
299299
"""
300300

301-
ast_query = DropView(names=[name])
301+
ast_query = DropView(names=[Identifier(name)])
302302

303303
self.query(ast_query.to_string()).fetch()
304304

@@ -452,7 +452,7 @@ def drop_model(self, name: str):
452452
453453
:param name: name of the model
454454
"""
455-
ast_query = DropPredictor(name=name)
455+
ast_query = DropPredictor(name=Identifier(name))
456456
self.query(ast_query.to_string()).fetch()
457457

458458
def drop_model_version(self, name: str, version: int):

mindsdb_sdk/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def drop_database(self, name: str):
101101
102102
:param name: name of integration
103103
"""
104-
ast_query = DropDatabase(name=name)
104+
ast_query = DropDatabase(name=Identifier(name))
105105
self.api.sql_query(ast_query.to_string())
106106

107107
def get_database(self, name: str) -> Database:
@@ -151,7 +151,7 @@ def drop_project(self, name: str):
151151
152152
:param name: name of the project
153153
"""
154-
ast_query = DropDatabase(name=name)
154+
ast_query = DropDatabase(name=Identifier(name))
155155
self.api.sql_query(ast_query.to_string())
156156

157157
def get_project(self, name: str = 'mindsdb') -> Project:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
requests
22
pandas == 1.3.5
3-
mindsdb-sql >= 0.6.7, < 0.7.0
3+
mindsdb-sql >= 0.7.0, < 0.8.0

tests/test_sdk.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ def test_flow(self, mock_post, mock_put):
9595

9696
self.check_database(database)
9797

98-
server.drop_database('pg1')
99-
check_sql_call(mock_post, 'DROP DATABASE pg1')
98+
server.drop_database('pg1-a')
99+
check_sql_call(mock_post, 'DROP DATABASE `pg1-a`')
100100

101101
# --------- projects -------------
102102
projects = server.list_projects()
@@ -114,8 +114,8 @@ def test_flow(self, mock_post, mock_put):
114114
mock_post, 'CREATE DATABASE proj1 WITH ENGINE = "mindsdb", PARAMETERS = {}')
115115
self.check_project(project, database)
116116

117-
server.drop_project('proj1')
118-
check_sql_call(mock_post, 'DROP DATABASE proj1')
117+
server.drop_project('proj1-1')
118+
check_sql_call(mock_post, 'DROP DATABASE `proj1-1`')
119119

120120
# test upload file
121121
response_mock(mock_post, pd.DataFrame([{'NAME': 'files'}]))
@@ -198,6 +198,9 @@ def check_project_views(self, project, database, mock_post, mock_get):
198198
project.drop_view('v2')
199199
check_sql_call(mock_post, 'DROP VIEW v2')
200200

201+
project.drop_view('v2-v')
202+
check_sql_call(mock_post, 'DROP VIEW `v2-v`')
203+
201204
@patch('requests.Session.post')
202205
def check_project_models(self, project, database, mock_post):
203206
# ----------- models --------------
@@ -262,8 +265,8 @@ def check_project_models(self, project, database, mock_post):
262265
assert model.name == 'm2'
263266
self.check_model(model, database)
264267

265-
project.drop_model('m3')
266-
check_sql_call(mock_post, f'DROP PREDICTOR m3')
268+
project.drop_model('m3-a')
269+
check_sql_call(mock_post, f'DROP PREDICTOR `m3-a`')
267270

268271
# the old way of join model with table
269272
sql = '''
@@ -360,14 +363,14 @@ def check_model(self, model, database, mock_post):
360363
query = database.query('select a from t1')
361364
pred_df = model.predict(query, params={'x': '1'})
362365

363-
check_sql_call(mock_post, f'SELECT m.* FROM (SELECT a FROM t1) JOIN {model.project.name}.{model_name} AS m USING x="1"')
366+
check_sql_call(mock_post, f'SELECT m.* FROM (SELECT a FROM t1) as t JOIN {model.project.name}.{model_name} AS m USING x="1"')
364367
assert (pred_df == pd.DataFrame(data_out)).all().bool()
365368

366369
# time series prediction
367370
query = database.query('select * from t1 where type="house" and saledate>latest')
368371
model.predict(query)
369372

370-
check_sql_call(mock_post, f"SELECT m.* FROM (SELECT * FROM t1 WHERE (type = 'house') AND (saledate > LATEST)) JOIN {model.project.name}.{model_name} AS m")
373+
check_sql_call(mock_post, f"SELECT m.* FROM (SELECT * FROM t1 WHERE (type = 'house') AND (saledate > LATEST)) as t JOIN {model.project.name}.{model_name} AS m")
371374
assert (pred_df == pd.DataFrame(data_out)).all().bool()
372375

373376
# ----------- model managing --------------

0 commit comments

Comments
 (0)