-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
[BUG] loc does not preserve datatype with a single element #36247
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
Hi, could you please provide your expected output? |
Hi, I'm editing the issue for clarity, sorry :D |
Sorry the issue formatting got shunt by the quote mechanism. I think it's a pure pandas problem, so the full version info might not be necessary |
The resulting Series of ```print(not_preserved.loc[0, ['A', 'B', 'C']].dtypes)`` is converted to a compatible dtype for all columns. There is no attempt to cast it back, when only a subset of columns is selected. You can not keep the dtype for all columns, if they are mixed like int, float and object, so I think this is intended? |
Ok, so the idea is that the row term of the |
this is a duplicate issue - there are several discussions about this if mixing float / int we can't easily do much about this as numpy upcasts add in an object column for example and a row selection will upcast to the compatible (which would be object) so actually we could change this by returning an object dtype Series if any mixed types - there is a perf concern here though - would have to check and see how big of a deal this is (and it's hard to tell in the real world) as i said i think there are some open issues about this |
Agreed that we have other issues about this. |
Opening a new issue as per @Dr-Irv suggestion on #31763
Sorry issue formatting got lost
As a test:
This is with pandas 1.0.3 but was already the case in 0.24.1, it seems that what changed was the behavior of a
replace
method downstream in my code.Originally posted by @glyg in #31763 (comment)
The text was updated successfully, but these errors were encountered: