ChristianCasazza / datasharing

4 stars 2 forks source link

French dataset can't be queried with columns with spaces #1

Open MyNameIsCalvinDavis opened 4 months ago

MyNameIsCalvinDavis commented 4 months ago
query = "SELECT `COMMUNE RECENSEE (R si recensée)` from francetax;"
client.query(query)

When selecting a random column like the one above, the following error is produced:

---------------------------------------------------------------------------
ParserException                           Traceback (most recent call last)
Cell In[240], line 2
      1 query = "SELECT `COMMUNE RECENSEE (R si recensée)` from francetax;"
----> 2 client.query(query)

File [~\Notebooks\French](http://localhost:8888/lab/tree/Notebooks/French%20Finance/datasharing/notebooks/~/Notebooks/French) Finance\datasharing\datasharing\datasharing.py:215, in DataSharingClient.query(self, query, new_table_name)
    213     print(f"Table {new_table_name} created from query.")
    214 else:
--> 215     result_df = self.conn.execute(query).fetchdf()
    216     print(f"Query: {query}")
    217     return result_df

ParserException: Parser Error: syntax error at or near "("

Is there a different way to access these columns? Otherwise I will be forced to just load the whole dataset into a single dataframe.

ChristianCasazza commented 4 months ago

query = 'SELECT "COMMUNE RECENSEE (R si recensée)" FROM francetax;' client.query(query)

Try running this query. The error seems to be because of the column names. Typically, it would be best to normalize all the column names so there aren’t any spaces or characters, but we didn’t with so many columns.

In this case, using double quotes could help.

On Sun, Jun 30, 2024 at 10:40 AM Calvin Davis @.***> wrote:

query = "SELECT COMMUNE RECENSEE (R si recensée) from francetax;"client.query(query)

When selecting a random column like the one above, the following error is produced:

---------------------------------------------------------------------------ParserException Traceback (most recent call last)Cell In[240], line 2 1 query = "SELECT COMMUNE RECENSEE (R si recensée) from francetax;"----> 2 client.query(query) File ~\Notebooks\French Finance\datasharing\datasharing\datasharing.py:215, in DataSharingClient.query(self, query, new_table_name) 213 print(f"Table {new_table_name} created from query.") 214 else:--> 215 result_df = self.conn.execute(query).fetchdf() 216 print(f"Query: {query}") 217 return result_df ParserException: Parser Error: syntax error at or near "("

Is there a different way to access these columns? Otherwise I will be forced to just load the whole dataset into a single dataframe.

— Reply to this email directly, view it on GitHub https://github.com/ChristianCasazza/datasharing/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXUNZFAR3FQPF575EZBOVILZKAKF7AVCNFSM6AAAAABKEFFJ5SVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM4DEMRYGU2TOMY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

MyNameIsCalvinDavis commented 4 months ago

Yeah looks like that did the trick. Thanks for the help!