-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Series iteration and to_dict methods *sometimes* return underlying storage type vs. Python object #25969
Comments
This probably occurs because Investigation and PR's welcome~ |
I'm having a go at this issue - quick note @boydgreenfield, it looks like iterating over a |
@drew-heenan Yes you're right I meant |
…#232. This is a workaround for a bug in Pandas. See pandas-dev/pandas#25969.
…#232. This is a workaround for a bug in Pandas. See pandas-dev/pandas#25969.
from #37648 (comment)
|
Some findings about the root cause of this casting issue on |
Code Sample, a copy-pastable example if possible
Problem description
pd.Series.to_dict
can return different types for objects depending on the composition of the series. This also affects iteration, e.g.,for k, v in series: ...
. This is inconsistent and, critically, leads to really weird and hard to debug issues downstream with types, especially around JSON conversion (the built-injson
module and many others will blow up when it encounters numpy dtypes).I cannot find this exact issue open in the issue tracker, though there are a number of related issues including:
DataFrame.to_dict
and inconsistent types (closed in0.24
): to_dict doesn't convert np.int64 to python integers (second try) #24908DataFrame.to_dict
calls (also closed recently): DataFrame.to_dict returning numpy scalars in certain cases #23753Expected Output
Expected output is for type coercion to Python ints to occur regardless of the exact column composition in the Series. #24908 is a related issue for
DataFrame
coercions with irregular behavior happening as a result.Output of
pd.show_versions()
INSTALLED VERSIONS
The text was updated successfully, but these errors were encountered: