mindsdb / dfsql

SQL interface to Pandas
GNU General Public License v3.0
51 stars 9 forks source link

dfsql.exceptions.dfsqlException: Table from_tables found in from_tables, but not in the SQL query. #15

Closed jdortuzar5 closed 3 years ago

jdortuzar5 commented 3 years ago

Hi, I'm trying to run the example in the README, but I'm not able to run it.

import pandas as pd
from dfsql import sql_query

df = pd.DataFrame({
     "animal": ["cat", "dog", "cat", "dog"],
     "height": [23,  100, 25, 71] 
 })

df.head()

sql_query('SELECT animal, height FROM "animals_df" WHERE height > 50', from_tables={"animals_df": df})

But I'm getting an error with the table name:

File "/home/ray/anaconda3/lib/python3.7/site-packages/dfsql/__init__.py", line 23, in sql_query
    raise dfsqlException(f"Table {table_name} found in from_tables, but not in the SQL query.")
dfsql.exceptions.dfsqlException: Table from_tables found in from_tables, but not in the SQL query.

I don't know if anyone is having the same issue. Thanks a lot for you help

btseytlin commented 3 years ago

Hello! The syntax has been changed so tables are provided as kwargs to sql_query, except for two reserved kwargs: ds_kwargs and custom_functions. So the correct way is this:

sql_query('SELECT animal, height FROM animals_df WHERE height > 50', animals_df=df)

I will update the docs, thank you

btseytlin commented 3 years ago

Resolved in https://github.com/mindsdb/dfsql/pull/16