-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
ENH: Upgrade Pandas SQLAlchemy code to be compatible with 2.0+ syntax #40686
Comments
There's also this warning being raised when using a connection that's already in a transaction:
|
After #43116, there is one final piece that remains. We need to refactor our SQL execution mechanism to match sqlalchemy 1.4/2.0. Currently, we convert query and params to DBAPI2.0 format and directly pass it to the connectable(engine or connection). But sqlalchemy 1.4/2.0 offers two paths for query execution. The My thought on this is that users should know how to work with sqlalchemy and are responsible for making sure all inputs are compliant with sqlachemy syntax. We simply pass user inputs to the corresponded sqlachemy function. |
Just noting that SQLAlchemy 2.0.0 was released a couple days ago, and Pinning |
Cannot connect with to_sql, apparently I cannot send the connection as an engine |
Pinning this for now to get more visibility |
Being asked to post here: my report in #51105 was a duplicate. Seems the Engine class has changed a bit in sqlalchemy2 (no execute attribute). In the docstring of
so a workaround for this case could be
|
as showed by smoke tests in pipeline https://github.com/andros21/pwrApp/actions/runs/4072297719 pandas postgresql is not yet operative with sqlalchemy 2.x pandas-dev/pandas#40686 downgrade and what for next month release
as showed by smoke tests in pipeline https://github.com/andros21/pwrApp/actions/runs/4072297719 pandas postgresql is not yet operative with sqlalchemy 2.x pandas-dev/pandas#40686 downgrade and what for next month release
Does this still need to be pinned? |
I'd keep it till 2.0 is out so that we don't get new issues as long as we are not compatible. Could also try unpinning it and re-pin when people open new issues? |
To properly use pd.read_sql having sqlachemy 2.0 consider:
your code should look like this: import pandas as pd query_string = "select * from table" I hope this helps! |
I am unpinning for now since 2.0 came out today which brings compatibility with SQLAlchemy 2.0 |
Is your feature request related to a problem?
As of SQLAlchemy 1.4, there is a new syntax available that will become the only syntax in version 2.0+. Pandas uses SQLAlchemy for performing SQL IO, particularly in
DataFrame.to_sql
andpd.read_sql
(viapd.read_sql_query
andpd.read_sql_table
). This usage is not compatible with the new SQLAlchemy syntax.Describe the solution you'd like
Upgrade Pandas SQLAlchemy code to be compatible with the new 1.4+/2.0+ syntax. An official guide for how to do so in a test-driven fashion is available here. Note that at least the following 2.0+ incompatibility warnings are issued (though this list is by no means exhaustive):
API breaking implications
The upgrade to the 2.0+ syntax is not backwards compatible, and even the upgrade to 1.4 may require some changes (though it is primarily an incremental step from 1.3). Since the range of SQLA features used by Pandas is limited, there should be little difficulty in supporting both >=2.0 (and hence also ~=1.4) and <=1.3.
Describe alternatives you've considered
The alternative is to pin
sqlalchemy<=2.0
, or to stop using the Pandas SQL IO functions.Additional context
The guide linked above shows how to discover SQLA compatibility issues, and then how to tweak the test suite to ensure that no issues are later introduced. Note that many of these upgrades are simple fixes (using
connection.execute
instead ofengine.execute
, not binding anEngine
into aMetaData
instance, not callingConnection.connect
, etc.) and that most are backwards-compatible with recent versions of SQLA.The text was updated successfully, but these errors were encountered: