-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
to_dict() on a boolean series sometimes returns numpy types instead of Python types #27616
Comments
IIUC you have a mixed dtype column and the inferencing is ultimately winding up in different spots based on how you select things (one stays an object and the other a bool), right? |
Yeah that seems like the right explanation. It seems the inferencing should ideally end up the same, unlike today. But even if it doesn't, shouldn't to_dict be expected to return a python type no matter what? I'm speculating on the expected behavior here. |
there are likely some embedded bugs here - welcome for you to have a look |
Not sure if this is the expected behavior, but it might be an underlying bug/undocumented feature in numpy:
|
xref numpy/numpy#14139 |
Based on the response in numpy/numpy#14139. Looks like when calling |
I am having this problem, except on integers (not a boolean series) using |
Sorry for my delay here. I followed up on numpy/numpy#14139 — the numpy folks suggest reliably converting to vanilla python types as follows:
Do you believe pandas should account for this edge case and call |
Problem description
I construct a
Series
in several ways that should give the same output fromto_dict()
, but instead I get different output types. In my case, this breaks downstream JSON serializers.The code sample below includes cases with correct output (
bool
) and incorrect (numpy.bool_
) -- see inline comments.Related issues, though none seem exactly the same: #13258, #13830, #16048, #17491, #19381, #20791, #23753, #23921, #24908, #25969
Code sample
This may explain what's going on:
That relates to #25969, where @mroeschke commented about a similar dtype discrepancy:
Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: