PERF: DataFrame.iloc[int] for EA dtypes#54508
Conversation
| cls = dtype.construct_array_type() | ||
| result = cls._empty((n,), dtype=dtype) | ||
| if isinstance(dtype, ExtensionDtype): | ||
| result = np.empty(n, dtype=object) |
There was a problem hiding this comment.
i expect this will be bad for e.g. DatetimeTZDtype
There was a problem hiding this comment.
I just tried it for DatetimeTZDtype("ns", "UTC") and it seems to be ok - and more performant in that case as well.
I think it's ok since each element is pulled out individually which ensures wrapping in Timestamp.
|
Is the issue that the relevant |
Yes. In the case pyarrow, really non-performant to iteratively set each element. |
|
Thanks @lukemanley |
|
I'm not wild about this. Seems to be papering over a hacky |
Fair enough. The |
Maybe a TODO note pointing back at the relevant part of this thread? |
doc/source/whatsnew/v2.1.0.rstfile if fixing a bug or adding a new feature.Perf improvement in
DataFrame.ilocwhen input is an integer and the dataframe is EA-backed. Most visible on wide frames.Also visible with
DataFramereductions of EA dtypes: