-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: set_index screws up the dtypes on empty DataFrames #38419
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
@Rufflewind I have tested this code snippet on the master branch and seems like it is not throwing the error. |
I get dtypes changing on 1.1.5, but expected behavior on 1.0.x, 1.2, and master. Because this is a regression in 1.1.x and I think we're okay to add tests in the rc phase, I'm going to mark this as Needs Tests and label as 1.2. @simonjayhawkins @jreback adjust if this is not correct. |
Then it's fixed on code? Cause I would like to make the tests and, if necessary, change the code. |
@IngErnestoAlvarez That's correct; but tests still need to be added. A PR to do so is very much welcome! |
I would like to work on this issue |
@IngErnestoAlvarez @jordi-crespo if possible it's good to avoid overlapping PRs (since only one PR will be merged) |
I have checked that this issue has not already been reported.
DataFrame.set_index() may not preserve dtype #30517 is similar in concept but relates to non-empty DataFrames, whereas the current bug is about empty ones.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Problem description
The dtype of the columns are silently changed when
.set_index
is called. This only happens when the DataFrame is empty, which suggests that this is an edge-case bug.This is problematic because the behavior of
.set_index()
varies depending on whether the DataFrame has any rows.Expected Output
The assertions should not fail.
Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: