Skip to content

Commit 5123da8

Browse files
committed
Merge pull request #3986 from mtkni/index_shift_drops_name
BUG: Index shift drops index name
2 parents ff4f313 + f1a3226 commit 5123da8

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ pandas 0.11.1
270270
- Indexing with a string with seconds resolution not selecting from a time index (:issue:`3925`)
271271
- csv parsers would loop infinitely if ``iterator=True`` but no ``chunksize`` was
272272
specified (:issue:`3967`), python parser failing with ``chunksize=1``
273+
- Fix index name not propogating when using ``shift``
273274

274275
.. _Gh3616: https://github.com/pydata/pandas/issues/3616
275276

pandas/core/index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def shift(self, periods=1, freq=None):
563563
return self
564564

565565
offset = periods * freq
566-
return Index([idx + offset for idx in self])
566+
return Index([idx + offset for idx in self], name=self.name)
567567

568568
def argsort(self, *args, **kwargs):
569569
"""

pandas/tests/test_index.py

+3
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ def test_shift(self):
204204
shifted = self.dateIndex.shift(1, 'B')
205205
self.assert_(np.array_equal(shifted, self.dateIndex + offsets.BDay()))
206206

207+
shifted.name = 'shifted'
208+
self.assertEqual(shifted.name, shifted.shift(1, 'D').name)
209+
207210
def test_intersection(self):
208211
first = self.strIndex[:20]
209212
second = self.strIndex[:10]

0 commit comments

Comments
 (0)