YuvrajLamba01 commented on issue #50667:
URL: https://github.com/apache/arrow/issues/50667#issuecomment-7143318053
For anyone following this slowdown and investigating the root cause across
PyArrow and pandas:
The behavior introduced in PyArrow 25 (PR #49694 / GH-15047) returning
`zoneinfo.ZoneInfo("UTC")` from `to_pandas_dtype()` / boxing is working as
designed. The reason the regression appears specifically in PyArrow 25 + pandas
is downstream in pandas' common type resolution when concatenating datasets
with mixed time units (e.g. legacy pandas 2 / PyArrow Parquet files in `ns`
resolution with pandas 3.x `us` resolution):
1. When time units match (e.g. `us` + `us`), `find_common_type` in pandas
takes `lib.dtypes_all_equal`, where `DatetimeTZDtype.__eq__` delegates to
`tz_compare(self.tz, other.tz)`. Because `tz_compare` treats `ZoneInfo("UTC")`
and `datetime.timezone.utc` as equal, matching resolutions stay fast.
2. When time units differ (e.g. `ns` Parquet dataset + `us` dataset),
`find_common_type` invokes `DatetimeTZDtype._get_common_dtype`
(`pandas/core/dtypes/dtypes.py`). That method checked `t.tz == self.tz` using
Python's identity/equality operator (`==`) rather than `tz_compare`.
- `zoneinfo.ZoneInfo("UTC") == datetime.timezone.utc` is `False`.
- `_get_common_dtype` therefore returns `None`, and `find_common_type`
falls back to `object`.
- On DataFrame columns, this silently casts the column to `dtype('O')`.
- On `DatetimeIndex`, `.append` and `pd.concat` fall back through object
boxing and re-parses all timestamps via `objects_to_datetime64`, creating the
reported ~180x–350x slowdown on 1M rows.
We have diagnosed and root-caused the issue in `pandas`, added regression
tests, and opened upstream issue and PR:
- pandas issue: https://github.com/pandas-dev/pandas/issues/72318
- pandas PR: https://github.com/pandas-dev/pandas/pull/72319
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]