Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
In [1]: df = pd.DataFrame({'ts': [pd.Timestamp('20230101 00:00:00+00:00')]})
[PYFLYBY] import pandas as pd
In [2]: df.to_parquet("~/tmp/test.parquet")
In [3]: with pd.option_context("mode.dtype_backend", "pyarrow"):
...: df2 = pd.read_parquet("~/tmp/test.parquet")
...:
In [4]: df2
Out[4]:
ts
0 2023-01-01 00:00:00+00:00
In [5]: df2.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1 entries, 0 to 0
Data columns (total 1 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 ts 1 non-null timestamp[us, tz=UTC][pyarrow]
dtypes: timestamp[us, tz=UTC][pyarrow](1)
memory usage: 137.0 bytes
In [6]: df2.ts.dt.tz_localize(None)
Out[6]:
0 2023-01-01 00:00:00
Name: ts, dtype: timestamp[us][pyarrow]
In [7]: df2.ts.dt.tz_convert('America/Chicago')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [7], line 1
----> 1 df2.ts.dt.tz_convert('America/Chicago')
AttributeError: 'ArrowTemporalProperties' object has no attribute 'tz_convert'
Issue Description
I think https://github.com/pandas-dev/pandas/pull/50954 might have missed adding an implementation for tz_convert
to ArrowTemporalProperties
(maybe this was by design?). With mode.dtype_backend='pyarrow'
, our existing dataframes are being loaded as timestamp[us, tz=UTC][pyarrow]
, but any calls to tz_convert fail.
Expected Behavior
Ideally we can implement tz_convert
natively so that it's fast.
If not, I think I'd prefer that tz_convert be monkey-patched in with a conversion to numpy data type, then tz_convert, then back to PyArrow backend (assuming that the conversion is lossless) so that existing APIs don't break when the dtype_backend changes. A warning might be appropriate there (so users know why the call might be slow, though I think it should still be pretty quick).
Installed Versions
Comment From: jbrockmendel
cc @mroeschke
Comment From: mroeschke
Thanks. The current version of pyarrow (11) doesn't have a compute function equivalent to "tz convert", so this should have ideally raised a NotImplementedError
Comment From: rok
pc.cast
wold enable this I believe.