Skip to content

Commit b9062c3

Browse files
committed
BUG: Fix #61222: Keep index name when resampling with pyarrow dtype
1 parent 04356be commit b9062c3

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

doc/source/whatsnew/v2.3.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Groupby/resample/rolling
169169

170170
Reshaping
171171
^^^^^^^^^
172-
-
172+
- :meth:`DataFrame.resample` was not keeping the index name when the index had :class:`pyarrow` datetime dtype (:issue:`61222`)
173173
-
174174

175175
Sparse

pandas/core/resample.py

+2
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,9 @@ def _wrap_result(self, result):
517517
result.name = getattr(obj, "name", None)
518518

519519
if self._timegrouper._arrow_dtype is not None:
520+
obj = self.obj
520521
result.index = result.index.astype(self._timegrouper._arrow_dtype)
522+
result.index.name = getattr(obj.index, "name", None)
521523

522524
return result
523525

pandas/tests/resample/test_datetime_index.py

+10
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,16 @@ def test_arrow_timestamp_resample(tz):
21552155
tm.assert_series_equal(result, expected)
21562156

21572157

2158+
@td.skip_if_no("pyarrow")
2159+
def test_arrow_timestamp_resample_keep_index_name():
2160+
# https://github.com/pandas-dev/pandas/issues/61222
2161+
idx = Series(date_range("2020-01-01", periods=5), dtype="timestamp[ns][pyarrow]")
2162+
expected = Series(np.arange(5, dtype=np.float64), index=idx)
2163+
expected.index.name = "index_name"
2164+
result = expected.resample("1D").mean()
2165+
assert result.index.name == expected.index.name
2166+
2167+
21582168
@pytest.mark.parametrize("freq", ["1A", "2A-MAR"])
21592169
def test_resample_A_raises(freq):
21602170
msg = f"Invalid frequency: {freq[1:]}"

0 commit comments

Comments
 (0)