Skip to content

DOC: pandas.DataFrame.to_sql does not document that it creates a table index for index columns #54712

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

Closed
1 task done
mattatark opened this issue Aug 23, 2023 · 2 comments · Fixed by #54988
Closed
1 task done
Assignees
Labels
Docs Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@mattatark
Copy link

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/dev/reference/api/pandas.DataFrame.to_sql.html#pandas.DataFrame.to_sql

Documentation problem

As far as I can tell, pandas.DataFrame.to_sql creates a table index when creating a table and including the index of the dataframe. This is unexpected, and undocumented. See this line that I believe is responsible for this. Here's a link to the relevant SQLAlchemy docs for that constructor input.

Suggested fix for documentation

I'd recommend updating the text field for the index input:

Write DataFrame index as a column. Uses index_label as the column name in the table. Creates a table index for this column.

Or something like that. I DO think that this behavior is generally undesired and should be removed, or have an input that should default to False, but at least documenting it will save others from hours of time looking through the code base to figure this out.

@mattatark mattatark added Docs Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 23, 2023
@pauluhlenbruck
Copy link
Contributor

take

@pauluhlenbruck
Copy link
Contributor

I will start working on this issue during the upcoming weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants