From f1a3226aaae5fc35bb6987d7e39cc35adbc19c29 Mon Sep 17 00:00:00 2001 From: Mike Kelly Date: Fri, 21 Jun 2013 16:36:46 -0400 Subject: [PATCH] Index.shift() drops index name --- doc/source/release.rst | 1 + pandas/core/index.py | 2 +- pandas/tests/test_index.py | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index afca7511bf11f..07489a140c018 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -270,6 +270,7 @@ pandas 0.11.1 - Indexing with a string with seconds resolution not selecting from a time index (:issue:`3925`) - csv parsers would loop infinitely if ``iterator=True`` but no ``chunksize`` was specified (:issue:`3967`), python parser failing with ``chunksize=1`` + - Fix index name not propogating when using ``shift`` .. _Gh3616: https://github.com/pydata/pandas/issues/3616 diff --git a/pandas/core/index.py b/pandas/core/index.py index a5880b9f18670..c06c46cde36c8 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -563,7 +563,7 @@ def shift(self, periods=1, freq=None): return self offset = periods * freq - return Index([idx + offset for idx in self]) + return Index([idx + offset for idx in self], name=self.name) def argsort(self, *args, **kwargs): """ diff --git a/pandas/tests/test_index.py b/pandas/tests/test_index.py index 7ce4a11229561..d9808ab48ca41 100644 --- a/pandas/tests/test_index.py +++ b/pandas/tests/test_index.py @@ -204,6 +204,9 @@ def test_shift(self): shifted = self.dateIndex.shift(1, 'B') self.assert_(np.array_equal(shifted, self.dateIndex + offsets.BDay())) + shifted.name = 'shifted' + self.assertEqual(shifted.name, shifted.shift(1, 'D').name) + def test_intersection(self): first = self.strIndex[:20] second = self.strIndex[:10]