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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PEP 8 compliance edits
  • Loading branch information
redbullpeter committed Feb 16, 2017
commit 2f4fbba9962d4a68610296eab9636276acb0ca97
3 changes: 2 additions & 1 deletion pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(((text_type(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.

idx_type, True))

column_names_and_types += [
(text_type(self.frame.columns[i]),
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,11 @@ def test_to_sql_index_label(self):
if_exists='replace')
frame = sql.read_sql_query('SELECT * FROM test_index_label', self.conn)
self.assertEqual(frame.columns[0], '0',
"Integer index label not written to database")
"Integer index label not written to database")

temp_frame.index.name = None
sql.to_sql(temp_frame, 'test_index_label', self.conn,
if_exists='replace', index_label= 0)
if_exists='replace', index_label=0)
frame = sql.read_sql_query('SELECT * FROM test_index_label', self.conn)
self.assertEqual(frame.columns[0], '0',
"Integer index label not written to database")
Expand Down