-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: pandas.to_sql raises unexpected column error if data contains -numpy.inf #34431
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
This runs fine on the 1.0. master. The complete snippet I ran is: import pandas
import numpy
from sqlalchemy import create_engine
engine = create_engine('sqlite://', echo=False)
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 Output of pd.show_versions()INSTALLED VERSIONScommit : 62c7dd3 pandas : 1.1.0.dev0+1681.g62c7dd3e7.dirty |
Would take a test for this if anyone would like to add |
This might depend on the database you are using (and the database driver). For example, the example using sqlite also works with pandas 0.23. (now, it's still good to actually test this for sqlite) |
* TST: pd.to_sql for dataframes with -np.inf (#34431) * DOC: updated what's new (#34431) * DOC: improved entry (#34431) * TST: moved to _TestSQLAlchemy + added round trips * TST: rename + add comment with GH issue # * TST: rewrote using pytest.mark.parametrize for arg to DataFrame * TST: removed underscore from _input * DOC: added double backtick to np.inf & removed extraneous space * TST: pd.to_sql for dataframes with -np.inf (#34431) * DOC: updated what's new (#34431) * DOC: improved entry (#34431) * TST: moved to _TestSQLAlchemy + added round trips * TST: rename + add comment with GH issue # * TST: rewrote using pytest.mark.parametrize for arg to DataFrame * TST: removed underscore from _input * DOC: added double backtick to np.inf & removed extraneous space * BUG: add catch for MySQL error with np.inf * use regex for string match + add runtime import * clean up regex * TST: update to catch error for -np.inf with MySQL * DOC: resolved conflict in whatsnew * TST: update test_to_sql_with_neg_npinf * fixed error handler syntax in SQLDatabase.to_sql * fixed error handler syntax in SQLDatabase.to_sql * TST: added an xfail test for npinf entries with mysql * fixed imports * added reference to GH issue * fixed test_to_sql_with_npinf error catch * fixed spelling error in message (can not -> cannot) * DOC: added info re MySQL ValueError to whatsnew * fixed variable name in to_sql * replaced sqlalchemy's dialect.name with flavor * fixed typo in test_to_sql-with-npinf
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
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 fieldinfe0
.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
The text was updated successfully, but these errors were encountered: