Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, MetaData
engine = create_engine("postgresql+psycopg2://postgres:postgres@localhost:5432/postgres")
meta = MetaData()
students = Table(
'students', meta,
Column('id', Integer, primary_key = True),
Column('name', String),
Column('lastname', String),
)
meta.create_all(engine)
query = "SELECT * FROM students"
df = pd.read_sql(sql=query, con=engine)
print(df.head())
Issue Description
This is an SQL Alchemy version issue. Works fine with SQLAlchemy == 1.4.46; Does not work with 2.0.0
Traceback (most recent call last):
File "C:\Users\DM_wo\Documents\Rich Insight\reports\asana-clockify\slack-notifier\pandas_bug.py", line 7, in <module>
monthly_profitability_df = pd.read_sql(sql=query, con=engine)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\DM_wo\Documents\Rich Insight\reports\asana-clockify\slack-notifier\venv\Lib\site-packages\pandas\io\sql.py", line 590, in read_sql
return pandas_sql.read_query(
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\DM_wo\Documents\Rich Insight\reports\asana-clockify\slack-notifier\venv\Lib\site-packages\pandas\io\sql.py", line 1560, in read_query
result = self.execute(*args)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\DM_wo\Documents\Rich Insight\reports\asana-clockify\slack-notifier\venv\Lib\site-packages\pandas\io\sql.py", line 1405, in execute
return self.connectable.execution_options().execute(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'OptionEngine' object has no attribute 'execute'
Expected Behavior
Expected behaviour is that it would return an empty dataframe, as it does with previous versions of SQLAlchemy.
$ python pandas_bug.py
Empty DataFrame
Columns: [id, name, lastname]
Index: []
Installed Versions
INSTALLED VERSIONS
commit : 8dab54d6573f7186ff0c3b6364d5e4dd635ff3e7 python : 3.11.1.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.22621 machine : AMD64 processor : AMD64 Family 23 Model 96 Stepping 1, AuthenticAMD byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : English_United Kingdom.1252
pandas : 1.5.2 numpy : 1.24.1 pytz : 2022.7.1 dateutil : 2.8.2 setuptools : 65.5.0 pip : 23.0 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : 3.0.7 lxml.etree : None html5lib : None pymysql : None psycopg2 : 2.9.5 jinja2 : None IPython : None pandas_datareader: None bs4 : None bottleneck : None brotli : None fastparquet : None fsspec : None gcsfs : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : 3.1.0 pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : None snappy : None sqlalchemy : 2.0.0 tables : None tabulate : None xarray : None xlrd : None xlwt : None zstandard : None tzdata : None
Comment From: RMagician
duplicate of [#51015]