-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
BUG: to_sql convert index name to string (#15404) #15423
BUG: to_sql convert index name to string (#15404) #15423
Conversation
…o_sql errors with numeric index name - needs conversion to string
@redbullpeter Thanks! Can you add a test case for this? (in pandas/tests/io/test_sql.py) You can put the test in the |
While writing the test cases I discovered I jumped the gun on this. Will probably have to rescind the pull request. |
OK done. For a while there it seemed like I was going down a rabbit hole that got more confusing as I picked at it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Only very minor comment
pandas/io/sql.py
Outdated
@@ -750,7 +750,8 @@ def _get_column_names_and_types(self, dtype_mapper): | |||
for i, idx_label in enumerate(self.index): | |||
idx_type = dtype_mapper( | |||
self.frame.index.get_level_values(i)) | |||
column_names_and_types.append((idx_label, idx_type, True)) | |||
column_names_and_types.append(((text_type(idx_label)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor issue, but I think you have here one pair of brackets that is not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Three lines further down the same kind of type_text conversion was done with a set of extra brackets. I just copied the style for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then you can remove it in both places. This is just redundant in python syntax, and not enhancing readability IMO (which could be a reason to have redundant chars)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it from my changes. Left the other one alone as on closer inspection the brackets were not extraneous after all, the line breaks just made it hard to see the pairing.
Codecov Report
@@ Coverage Diff @@
## master #15423 +/- ##
==========================================
- Coverage 90.37% 90.37% -0.01%
==========================================
Files 135 135
Lines 49440 49454 +14
==========================================
+ Hits 44681 44693 +12
- Misses 4759 4761 +2
Continue to review full report at Codecov.
|
@redbullpeter Thanks a lot! |
@redbullpeter Whoops, forgot to ask you for a whatsnew note, so quickly added it: 54b6c6e |
…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
…rs with numeric index name - needs conversion to string
git diff upstream/master | flake8 --diff