-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: Not silently ignore violation of minimal required version of SQLAlchemy #57178
Comments
Thanks for the report! It looks like this was changed in #45679 to allow for other dependencies. Perhaps the logic could be changed there so that when SQLAlchemy is used, we do check that the version is satisfied. Further investigations and PRs to fix are welcome! |
I have attempted to recreate the issue in a fresh environment with from sqlalchemy import create_engine
import pandas as pd
engine = create_engine("sqlite:///:memory:")
df = pd.DataFrame({
"id": [1, 2, 3],
"name": ["Alice", "Bob", "Charlie"]
})
df.to_sql("Person", engine, index=False)
sql_query = "SELECT * FROM Person"
result = pd.read_sql_query(sql_query, engine)
print(result)
|
The issue is not that it works with SQLAlchemy 2 but that it gives no clue why it does not work with SQLAlchemy < 2.x To replicate install SQLAlchemy==1.4 and rerun the code-snippet from above. This results in..
which is surprising given that we just created the engine with SQLAlchemy. And it gives the user no clue that this is due to violation of version requirement. It would be obvious what is the issue if the version check in
pandas/pandas/compat/_optional.py Line 152 in f538741
... instead of just silently returning None (which only later leads to the miss-leading error from above.) |
Seems related #57049, whether to support Sqlalchemy 1.4 is under discussion. |
I think this is related. It should state that sqlalchemy <2.0 is not supported instead of "not installed". import sqlalchemy
print("sqlalchemy Version:", sqlalchemy.__version__)
pd.read_sql("select * from osm_point limit 1", connection_string) sqlalchemy Version: 1.4.52
...
ImportError: Using URI string without sqlalchemy installed. |
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
Observation
After upgrading to Pandas 2.2.0 calling
read_sql_query
with a SQLAlchemy query on an SQLAlchemy connection yielded"Query must be a string unless using sqlalchemy."
without any indication why or what may have broken with the upgrade.Analysis
Tracking the problem down it was found that
pandasSQL_builder
(code) callssqlalchemy = import_optional_dependency("sqlalchemy", errors="ignore")
to resolve the optional SQLAlchemy package (which was installed in my case)Due to
errors="ignore"
the violation of the minimal required version for SQLAlchemy does not lead to a warn or raise (code) but just silently returns withNone
.This in turn lets
pandasSQL_builder
silently default toSQLiteDatabase(con)
.Feature Description
Proposed improvement
Do not ignore the minimal version violation in
import_optional_dependency
in this context but make it obvious. For example by introducing an additional "errors"-mode likeimport_optional_dependency("sqlalchemy", errors="raise-on-version-violation")
.Alternative Solutions
./.
Additional Context
No response
The text was updated successfully, but these errors were encountered: