Skip to content
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

Merged
merged 4 commits into from
Feb 17, 2017

Conversation

redbullpeter
Copy link
Contributor

@redbullpeter redbullpeter commented Feb 16, 2017

…rs with numeric index name - needs conversion to string

…o_sql errors with numeric index name - needs conversion to string
@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Feb 16, 2017

@redbullpeter Thanks!

Can you add a test case for this? (in pandas/tests/io/test_sql.py) You can put the test in the _TestSQLApi class

@jorisvandenbossche jorisvandenbossche added Bug IO SQL to_sql, read_sql, read_sql_query labels Feb 16, 2017
@redbullpeter
Copy link
Contributor Author

While writing the test cases I discovered I jumped the gun on this. Will probably have to rescind the pull request.

@redbullpeter
Copy link
Contributor Author

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.

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a 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)),
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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)

Copy link
Contributor Author

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.

@jorisvandenbossche jorisvandenbossche added this to the 0.20.0 milestone Feb 16, 2017
@codecov-io
Copy link

codecov-io commented Feb 16, 2017

Codecov Report

Merging #15423 into master will decrease coverage by -0.01%.
The diff coverage is 100%.

@@            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
Impacted Files Coverage Δ
pandas/io/sql.py 94.79% <100%> (ø)
pandas/tseries/index.py 95.32% <ø> (-0.1%)
pandas/core/frame.py 97.82% <ø> (-0.05%)
pandas/core/generic.py 96.33% <ø> (ø)
pandas/tools/concat.py 97.62% <ø> (ø)
pandas/io/excel.py 79.64% <ø> (+0.24%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a8883b...e9a4f3a. Read the comment docs.

@jorisvandenbossche jorisvandenbossche changed the title Converted index name to string to fix issue #15404 - BUG: to_sql erro… BUG: to_sql convert index name to string (#15404) Feb 17, 2017
@jorisvandenbossche jorisvandenbossche merged commit f4e672c into pandas-dev:master Feb 17, 2017
@jorisvandenbossche
Copy link
Member

@redbullpeter Thanks a lot!

jorisvandenbossche added a commit that referenced this pull request Feb 17, 2017
@jorisvandenbossche
Copy link
Member

@redbullpeter Whoops, forgot to ask you for a whatsnew note, so quickly added it: 54b6c6e

@redbullpeter redbullpeter deleted the issue_#15404 branch February 17, 2017 13:16
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this pull request Mar 21, 2017
…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
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this pull request Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO SQL to_sql, read_sql, read_sql_query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: to_sql errors with numeric index name - needs conversion to string
3 participants