Skip to content

ENH: raise exception when sqlalchemy is required for database string URI #11920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2016
Merged

ENH: raise exception when sqlalchemy is required for database string URI #11920

merged 1 commit into from
Aug 10, 2016

Conversation

ksindi
Copy link
Contributor

@ksindi ksindi commented Dec 29, 2015

  • I get a cryptic error AttributeError: 'str' object has no attribute 'cursor' if sqlalchemy is not installed and I pass a database string URI to pandas.read_sql. I think the error should be made more explicit.
  • Also I think there is a shadowing issue with_SQLALCHEMY_INSTALLED in _engine_builder.
/opt/conda/lib/python3.4/site-packages/pandas/io/sql.py in read_sql_query(sql, con, index_col, coerce_float, params, parse_dates, chunksize)
    427     return pandas_sql.read_query(
    428         sql, index_col=index_col, params=params, coerce_float=coerce_float,
--> 429         parse_dates=parse_dates, chunksize=chunksize)
    430 
    431 

/opt/conda/lib/python3.4/site-packages/pandas/io/sql.py in read_query(self, sql, index_col, coerce_float, params, parse_dates, chunksize)
   1569 
   1570         args = _convert_params(sql, params)
-> 1571         cursor = self.execute(*args)
   1572         columns = [col_desc[0] for col_desc in cursor.description]
   1573 

/opt/conda/lib/python3.4/site-packages/pandas/io/sql.py in execute(self, *args, **kwargs)
   1532             cur = self.con
   1533         else:
-> 1534             cur = self.con.cursor()
   1535         try:
   1536             if kwargs:

AttributeError: 'str' object has no attribute 'cursor'

@jreback
Copy link
Contributor

jreback commented Dec 29, 2015

this would need some tests

@jreback jreback added the IO SQL to_sql, read_sql, read_sql_query label Dec 29, 2015
@@ -617,9 +618,11 @@ def _engine_builder(con):

except ImportError:
_SQLALCHEMY_INSTALLED = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also set this to True when it is imported?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no, sorry, this is good (the _is_sqlalchemy_connectable does more than just setting the global value to True, so that should still be run)

@jorisvandenbossche
Copy link
Member

@ksindi Thanks for the catch!

For adding a test, you can put it in TestSQLiteFallbackApi I think (this class is not skipped if sqlalchemy is not installed), and then let the test itself skip if SQLALCHEMY_INSTALLED is True.
I am only not sure if there is a test build that has no sqlalchemy installed

@ksindi
Copy link
Contributor Author

ksindi commented Dec 31, 2015

@jorisvandenbossche thanks. I'll change to ImportError and run tests.

@jreback
Copy link
Contributor

jreback commented Jan 6, 2016

@jorisvandenbossche status of this?

@ksindi
Copy link
Contributor Author

ksindi commented Jan 6, 2016

@jreback Haven't had a chance to work on it.

@jreback
Copy link
Contributor

jreback commented Jan 20, 2016

pls rebase / update

@jreback
Copy link
Contributor

jreback commented Mar 12, 2016

can you rebase/update

@jreback
Copy link
Contributor

jreback commented May 7, 2016

can you rebase / update

@ksindi
Copy link
Contributor Author

ksindi commented May 27, 2016

Get same error if mysql driver (e.g. mysqldb) is not installed.

@jorisvandenbossche
Copy link
Member

@ksindi Would you have some time to update this?

@ksindi
Copy link
Contributor Author

ksindi commented Jul 25, 2016

@jorisvandenbossche I will get this done this week. Sorry for the delay.

@codecov-io
Copy link

codecov-io commented Jul 30, 2016

Current coverage is 85.29% (diff: 50.00%)

Merging #11920 into master will decrease coverage by <.01%

@@             master     #11920   diff @@
==========================================
  Files           139        139          
  Lines         50138      50140     +2   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits          42769      42769          
- Misses         7369       7371     +2   
  Partials          0          0          

Powered by Codecov. Last update 3186fef...20678db

@ksindi
Copy link
Contributor Author

ksindi commented Jul 30, 2016

@jorisvandenbossche added test

@ksindi
Copy link
Contributor Author

ksindi commented Aug 3, 2016

@jreback not sure why getting build error. Let me know if there's anything else I need to do on my end.

@jreback
Copy link
Contributor

jreback commented Aug 3, 2016

pls add a whatsnew note.

@jreback
Copy link
Contributor

jreback commented Aug 3, 2016

@ksindi
Copy link
Contributor Author

ksindi commented Aug 3, 2016

What's New

  • Raise ImportError when sqlalchemy is not installed and a connection string is used

@ksindi
Copy link
Contributor Author

ksindi commented Aug 3, 2016

@jreback thanks will fix linting error tonight

@ksindi ksindi closed this Aug 6, 2016
@ksindi ksindi reopened this Aug 6, 2016
@ksindi
Copy link
Contributor Author

ksindi commented Aug 6, 2016

@jreback just an fyi I fixed linting errorr

@ksindi ksindi changed the title Raise exception when sqlalchemy is required for database string URI ENH: raise exception when sqlalchemy is required for database string URI Aug 6, 2016
@jreback jreback added this to the 0.19.0 milestone Aug 6, 2016
@jreback
Copy link
Contributor

jreback commented Aug 6, 2016

lgtm. @jorisvandenbossche

@jorisvandenbossche
Copy link
Member

@ksindi Thanks!

@jorisvandenbossche jorisvandenbossche merged commit cce7993 into pandas-dev:master Aug 10, 2016
jorisvandenbossche added a commit that referenced this pull request Aug 10, 2016
jorisvandenbossche added a commit that referenced this pull request Aug 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas IO SQL to_sql, read_sql, read_sql_query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants