Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Mysql Create Table
DROP TABLE IF EXISTS test.my_table;
CREATE TABLE test.my_table
(
`id` VARCHAR(3),
PRIMARY KEY(id),
`price` DOUBLE NULL,
`%_variation` DOUBLE NULL
);
INSERT INTO test.my_table VALUES('101', 25.2, 0.1);
INSERT INTO test.my_table VALUES('102', 40.2, -0.5);
INSERT INTO test.my_table VALUES('103', 55.2, 0.9);
import pandas as pd
from sqlalchemy import create_engine
DB_PW = 'My_password'
DB_PORT = '3306'
DB_NAME = 'Test'
db_uri = f'mysql+mysqldb://root:{DB_PW}@localhost:{DB_PORT}'
engine = create_engine(f'{db_uri}/{DB_NAME}')
df = pd.read_sql_table(table_name='my_table', con=engine, schema=DB_NAME)
Problem description
[this should explain why the current behaviour is a problem and why the expected output is a better solution]
As you can see above, the %_variation
column is read as %%_variation
in the SELECT statement.
But the %%_variation
column is not present in the database and thus reading this table from the database provides an error.
Expected Output
I expect pandas to read the table from the database.
I tried reading with pandas version 1.0.5 and I was able to read the table from the database without any problem.
Output of pd.show_versions()
INSTALLED VERSIONS
commit : db08276
python : 3.7.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.1.3
numpy : 1.19.0
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 50.3.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.2.9
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.19
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
numba : None