-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DataFrame.loc/iloc fails to update object with new dtype #24269
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
Something that might be useful to note is that when indexing with a single label we get the expected output. For example:
However as you mentioned before:
So the issue might have something to do with casting and indexing the dataframe with a list of labels versus single label? |
I'm not sure if this fix is the right way to resolve the problem, but I've added another control statement so that updating dataframe values corresponding to a list of labels is handled the same way as updating dataframe values corresponding to a single label. The performance test pandas/pandas/core/indexing.py Lines 618 to 652 in 04a0eac
Changes were made based on my previous comment. When indexing via single label the code goes through lines 624-631 (see code snipped above). When indexing via a list of labels the code goes through lines 649-652. |
on master the first case fails to convert now as well.
|
Why does this problem so hard to fix? It is 2024 now and the bug still exist. 😭 Not only for numeric dtypes, but also for datetime dtypes (I think change date strings to datetime is a common operation). |
Similar to #4312 and #5702, but this seems specific to object dtype -> new dytpe.
In this first case, we likely convert the whole block, even though we just wanted
A
.In this one, (maybe a different bug), we fail to convert
['a', 'b']
to float when they start out in an object block with other values.The text was updated successfully, but these errors were encountered: