-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: to_sql errors with numeric index name - needs conversion to string #15404
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
@redbullpeter Thanks for the report The reason for the error is the integer index name. If you set this to a string, it will work
So integer column names are not allowed for writing to sql. For columns, this is checked for, and the integers are converted to a string. This check apparently does not happen for the index name (which also becomes a column label in the sql table), and by keeping it as an int, an error is raised in the underlying sqlalchemy code. Fixes very welcome! |
I can probably do the fix for that. Will it be sufficient to naively convert an int to a string for the index column? |
Yes, I think it is just this line: Line 753 in 93f5e3a
text_type(..) , this is not done for the index label.You should confirm with a test that this indeed solves the issue. |
…o_sql errors with numeric index name - needs conversion to string
Reran the code sample above and got the expected outcomes. This worked for both using the sqlalchmey and sqlite3 packages. |
* Converted index name to string to fix issue #15404 - BUG: to_sql errors with numeric index name - needs conversion to string * Additional int to string conversion added. Associated test cases added. * PEP 8 compliance edits * Removed extraneous brackets
…ev#15423) * Converted index name to string to fix issue pandas-dev#15404 - BUG: to_sql errors with numeric index name - needs conversion to string * Additional int to string conversion added. Associated test cases added. * PEP 8 compliance edits * Removed extraneous brackets
Code Sample, a copy-pastable example if possible
Problem description
This errors as follows:
Commenting out the df.set_index line results in expected behaviour though with a simple integer index. Using sqlite3 as the library also results in errors.
Expected Output
Output of
pd.show_versions()
pandas: 0.19.2
nose: None
pip: 9.0.1
setuptools: 34.1.1
Cython: None
numpy: 1.12.0
scipy: None
statsmodels: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: None
boto: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: