BUG: pandas.to_sql raises unexpected column error if data contains -numpy.inf · Issue #34431 · pandas-dev/pandas (original) (raw)
- 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.
Code Sample, a copy-pastable example
import pandas import numpy pandas.DataFrame({'foo': [numpy.inf]}).to_sql('foobar1', engine) #ProgrammingError: inf can not be used with MySQL pandas.DataFrame({'foo': [-numpy.inf]}).to_sql('foobar2', engine) # OperationalError: (1054, "Unknown column 'infe0' in 'field list'") pandas.DataFrame({'foo': [-numpy.inf], 'infe0':['bar']}).to_sql('foobar3', engine) # inserts (foo:Null, infe0: 'bar') into db
Problem description
I'd expect consistent behaviour between numpy.inf
and -numpy.inf
. Raising ProgrammingError in both cases is clear for the user. Furthermore, the query send should not interpret -inf as field infe0
.
Expected Output
ProgrammingError: inf can not be used with MySQL
in all 3 cases.
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.7.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.19.76-linuxkit
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.23.4
pytest: None
pip: 20.0.2
setuptools: 40.6.2
Cython: None
numpy: 1.15.4
scipy: None
pyarrow: 0.11.1
xarray: None
IPython: 7.13.0
sphinx: None
patsy: None
dateutil: 2.8.1
pytz: 2019.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: 4.4.1
bs4: None
html5lib: None
sqlalchemy: 1.3.11
pymysql: None
psycopg2: None
jinja2: 2.11.2
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None