-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DEPR: pandas.io.sql.execute #50185
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
Comments
So When putting your query into read_sql it works as expected |
No impacts outside of |
Thx for pointing this out. Was not aware of that. Do we have public docstrings for this function? @fangchenli could you weight in here? Any reason that this is public? |
I don't think there are any public docstrings. I could change the PR to raise an error if the caller passes an |
This method was introduced in the initial commit of the SQL module in 2010 as a helper function. I don't think it's still relevant today. Removing it completely would be an even better option. |
Thx, then let’s raise an error if anything other than a connection is passed and let’s deprecate it to get rid of it in 3.0 |
take |
There is currently a bug in
pandas.io.sql.execute
on the main branch (not in any released versions). I created the bug in #49531 while working on #48576. In #49531, I changedSQLDatabase
to only accept aConnection
and not anEngine
, because sqlalchemy 2.0 restricts the methods that are available toEngine
. #49531 created bugs in bothread_sql
andpandas.io.sql.execute
, and I have an open PR to fixread_sql
in #49967.This reproduces the bug in
pandas.io.sql.execute
:Traceback when running on the main branch in pandas:
When running on pandas 1.5.2, there is no error.
After #49967,
SQLDatabase
acceptsstr
,Engine
, andConnection
, but inSQLDatabase.__init__
, aConnection
is created if it was not passed in, and anExitStack
is created to clean up theConnection
andEngine
if necessary. Cleanup happens either inSQLDatabase.__exit__
or at the end of the generator which is returned byread_sql
ifchunksize
is not None. What I'm not able to see is how to do the cleanup after the caller fetches the results ofpandas.io.sql.execute
. I have come up with two options so far:pandas.io.sql.execute
to require aConnection
, or else do not allow queries that return rows if astr
orEngine
is used.Result.freeze
to fetch the results before closing theSQLDatabase
context manager. The problem here is that it requires sqlalchemy 1.4.45, which was only released on 12/10/2022, due to a bug in prior versions: freeze does not work for textual SQL sqlalchemy/sqlalchemy#8963The text was updated successfully, but these errors were encountered: