-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
COMPAT: box int/floats in __iter__ #13258
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
cc @glaucouri |
interesting that numpy converts with |
There was a big debate in the early days about whether numpy indexing should return python scalars or what. The compromise was that it doesn't, but there is also this bolted on notion of "convert to a Python style object" put in to appease the other side. This python conversion API lost the battle for users and mindshare, and these days no one uses intentionally or even realizes that it's in there, but it's still in there. Specifically the python object API is OTOH |
To be honest, i'm puzzled as Jeff, the question is: Why in numpy algo you must convert a ndarray to a python list? Is this unequivocally to go in a python types (so is better to convert to native data types) ? I think is more clear to mantain always native types, without do any automatic conversion. Eventually if someone need to exit from this logic, he know exaclty what is doing, and why. I appreciate this approach used in pandas for Timestamp. my 50 cents. |
+1. When we iterate numpy dtype, can use |
This has just bitten me in a surprising way, along the lines of #16048: converting a dataframe to a dict results in an object that cannot be converted to json.
There seems to be no easy to way to generate a dict of purely Python types. Maybe one could hack something together using And before someone suggests |
@jstray actually there is an easy way PR to fix this issue! it's pretty straightforward :) |
@jreback what is the easy way? |
Thanks @jreback for your fix! This was way deeper into the Pandas codebase than I was qualified to go. |
Thanks @jreback ! This saves my butt! |
HUUUGE +1 |
xref #13236 as
.map
was recently clarified to box ints/floats (and all other dtypes) to python/pandas types (rather than numpy scalars).__iter__
should do the same (it already is done for datetimelikes), need to add for int/floats.Furthermore
Series.tolist()
also returns python types (#10904)This will make it more consistent with pandas iteration strategy.
We also already do this for
object
types.tolist()
let's fix for pure types
When solving this issue, also have to look at:
to_dict
to numpy/python scalar (Inconsistent type casting between DataFrame and Series #14216)The text was updated successfully, but these errors were encountered: