-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
iterrows: when upcasting to object, values are converted to python types #13468
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
see discussion #13236 should be the same (eg Python types) |
so after #17491 I think we could actually/should fix [260], but that's another item. |
Yes, I think this can actually be closed now, apart from a doc update to iterrows / itertuples to make it clear that it boxes to python / custom pandas types. |
i think ok to keep open for now I want to fix the scalar getting as well (will reirose for that) |
To fix |
There is something strange going on here. Taking an example from documentation:
But:
So it seems conversion to Python types happens only if there is some |
I don't think so, as in that example there are only numeric dtypes, so it makes sense to keep the row / Series as float dtype. I agree it is a bit confusing that it depends on whether there is a string column or not. But I think the dtype of the resulting Series of float vs object makes sense. |
@jorisvandenbossche is the only remaining issue here documenting the behavior? |
I found the same problem printing a dataframe. When printing an int column as [1992, 1993, 1994], prints [1992.0, 1993.0, 1994.0]. I tried
and nothing |
I know
iterrows
is not the most recommended function, but I noticed a strange behaviour (triggered by a problem of a geopandas user: geopandas/geopandas#348). When usingiterrows
on a df with mixed dtypes (so the resulting series is of object dtype), the numeric values are converted to python types, while withloc/iloc
the numpy types are preserved:Is this intentional? (it's a consequence of using
self.values
in the implementation, and numpy does this conversion to python types in an object array) And if so, is this worth documenting?(note it was actually the numpy types in an object dtyped series that caused an issue for the geopandas user, because fiona couldn't handle those numpy scalars in an object dtyped column, but that's not an issue to blame pandas)
The text was updated successfully, but these errors were encountered: