From 8930519abbf78f4d69aab2d5e87b1fa2acb47b91 Mon Sep 17 00:00:00 2001 From: jreback Date: Sun, 28 Jul 2013 19:35:29 -0400 Subject: [PATCH] BUG: Fix .iat indexing with a PeriodIndex GH4390 Series.get with negative indexers returns the same as [] --- doc/source/release.rst | 2 ++ doc/source/v0.13.0.txt | 1 + pandas/core/series.py | 2 +- pandas/tests/test_series.py | 2 +- pandas/tseries/tests/test_period.py | 9 +++++++++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index 198948259be15..779ec9852118d 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -62,6 +62,7 @@ pandas 0.13 - deprecated ``iterkv``, which will be removed in a future release (was just an alias of iteritems used to get around ``2to3``'s changes). (:issue:`4384`, :issue:`4375`, :issue:`4372`) + - ``Series.get`` with negative indexers now returns the same as ``[]`` (:issue:`4390`) **Experimental Features** @@ -87,6 +88,7 @@ pandas 0.13 dtypes, surfaced in (:issue:`4377`) - Fixed bug with duplicate columns and type conversion in ``read_json`` when ``orient='split'`` (:issue:`4377`) + - Fix ``.iat`` indexing with a ``PeriodIndex`` (:issue:`4390`) pandas 0.12 =========== diff --git a/doc/source/v0.13.0.txt b/doc/source/v0.13.0.txt index 11c5ef5fe80b9..d0fa99165cb82 100644 --- a/doc/source/v0.13.0.txt +++ b/doc/source/v0.13.0.txt @@ -29,6 +29,7 @@ API changes - deprecated ``iterkv``, which will be removed in a future release (was just an alias of iteritems used to get around ``2to3``'s changes). (:issue:`4384`, :issue:`4375`, :issue:`4372`) + - ``Series.get`` with negative indexers now returns the same as ``[]`` (:issue:`4390`) Enhancements ~~~~~~~~~~~~ diff --git a/pandas/core/series.py b/pandas/core/series.py index 0e995f47935a0..394a0e6cabbab 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1018,7 +1018,7 @@ def get_value(self, label): ------- value : scalar value """ - return self.index._engine.get_value(self, label) + return self.index.get_value(self, label) def set_value(self, label, value): """ diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index 151a97a281ad3..e117c624e7d53 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -629,7 +629,7 @@ def test_getitem_get(self): self.assertEqual(self.series[idx1], self.series[5]) self.assertEqual(self.objSeries[idx2], self.objSeries[5]) - self.assert_(self.series.get(-1) is None) + self.assertEqual(self.series.get(-1), self.series.get(self.series.index[-1])) self.assertEqual(self.series[5], self.series.get(self.series.index[5])) # missing diff --git a/pandas/tseries/tests/test_period.py b/pandas/tseries/tests/test_period.py index 03b1d89714f68..a5902ac718fa6 100644 --- a/pandas/tseries/tests/test_period.py +++ b/pandas/tseries/tests/test_period.py @@ -1323,6 +1323,15 @@ def test_as_frame_columns(self): ts = df['1/1/2000'] assert_series_equal(ts, df.ix[:, 0]) + def test_indexing(self): + + # GH 4390, iat incorrectly indexing + index = period_range('1/1/2001', periods=10) + s = Series(randn(10), index=index) + expected = s[index[0]] + result = s.iat[0] + self.assert_(expected == result) + def test_frame_setitem(self): rng = period_range('1/1/2000', periods=5) rng.name = 'index'