-
-
Notifications
You must be signed in to change notification settings - Fork 19.5k
Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
import io
data = '''agency_cd,site_no,datetime,tz_cd,144166_00060,144166_00060_cd,144167_00065,144167_00065_cd
USGS,9333500,2001-05-07 01:00:00,MDT,71.0,A:[91],,
USGS,9333500,2001-05-07 01:15:00,MDT,71.0,A:[91],,
USGS,9333500,2001-05-07 01:30:00,MDT,71.0,A:[91],,
USGS,9333500,2001-05-07 01:45:00,MDT,70.0,A:[91],,
USGS,9333500,2001-05-07 02:00:00,MDT,70.0,A:[91],,
USGS,9333500,2001-05-08 02:15:00,MDT,69.0,A:[91],,
USGS,9333500,2001-05-08 02:30:00,MDT,70.0,A:[91],,
USGS,9333500,2001-05-08 02:45:00,MDT,70.0,A:[91],,
USGS,9333500,2001-05-08 03:00:00,MDT,70.0,A:[91],,'''
df = pd.read_csv(io.StringIO(data), dtype_backend='pyarrow', engine='pyarrow')
def to_denver_time(df_, time_col, tz_col):
return (df_
.assign(**{tz_col: df_[tz_col].replace('MDT', 'MST7MDT')})
.groupby(tz_col)
[time_col]
.transform(lambda s: pd.to_datetime(s)
.dt.tz_localize(s.name, ambiguous=True)
.dt.tz_convert('America/Denver'))
.astype('timestamp[ns, America/Denver][pyarrow]')
)
def tweak_river(df_):
return (df_
.assign(datetime=to_denver_time(df_, 'datetime', 'tz_cd'))
.rename(columns={'144166_00060': 'cfs'})
.loc[:, ['datetime', 'cfs']]
.set_index('datetime')
)
dd = tweak_river(df)
# Check the dtype before grouping
print("Before pd.Grouper:")
print(f"Index dtype: {dd.index.dtype}")
# Use pd.Grouper to group by day
result = dd.groupby(pd.Grouper(freq='D')).median(numeric_only=True)
# Check the dtype after grouping
print("\nAfter pd.Grouper:")
print(f"Index dtype: {result.index.dtype}")Issue Description
When using pd.Grouper with a PyArrow-backed timestamp column, the resulting index is automatically converted from the PyArrow dtype (timestamp[ns, America/Denver][pyarrow]) to the numpy-backed dtype (datetime64[ns, America/Denver]). This conversion happens silently and is inconsistent with the goal of maintaining PyArrow types throughout the analysis pipeline.
This affects users working with PyArrow backend who want to maintain PyArrow types for performance and consistency reasons.
Expected Behavior
The resulting index after using pd.Grouper should maintain the original PyArrow dtype (timestamp[ns, America/Denver][pyarrow]) instead of converting to numpy's datetime64[ns, America/Denver].
Installed Versions
Details
INSTALLED VERSIONS
commit : 7242759
python : 3.11.13
python-bits : 64
OS : Darwin
OS-release : 24.6.0
Version : Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8
pandas : 3.0.0rc1
numpy : 2.4.0
dateutil : 2.9.0.post0
pip : 25.3
Cython : 3.2.2
sphinx : None
IPython : 9.8.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.14.3
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : 6.0.2
matplotlib : 3.10.7
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.5
psycopg2 : None
pymysql : None
pyarrow : 22.0.0
pyiceberg : None
pyreadstat : None
pytest : 9.0.2
python-calamine : None
pytz : 2025.2
pyxlsb : None
s3fs : None
scipy : 1.16.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
qtpy : None
pyqt5 : None