From a1c3027f2c634830558729cc5912f64ac716fe30 Mon Sep 17 00:00:00 2001 From: jreback Date: Tue, 1 Jul 2014 11:37:56 -0400 Subject: [PATCH] BUG: Bug in Series.get with a boolean accessor (GH7407) --- doc/source/v0.14.1.txt | 2 +- pandas/core/index.py | 2 +- pandas/tests/test_series.py | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/source/v0.14.1.txt b/doc/source/v0.14.1.txt index 42041cceeb81b..5a731ae3dcacf 100644 --- a/doc/source/v0.14.1.txt +++ b/doc/source/v0.14.1.txt @@ -173,7 +173,7 @@ Bug Fixes - Bug in timeops with non-aligned Series (:issue:`7500`) - Bug in timedelta inference when assigning an incomplete Series (:issue:`7592`) - Bug in groupby ``.nth`` with a Series and integer-like column name (:issue:`7559`) - +- Bug in ``Series.get`` with a boolean accessor (:issue:`7407`) - Bug in ``value_counts`` where ``NaT`` did not qualify as missing (``NaN``) (:issue:`7423`) - Bug in ``to_timedelta`` that accepted invalid units and misinterpreted 'm/h' (:issue:`7611`, :issue: `6423`) diff --git a/pandas/core/index.py b/pandas/core/index.py index 4d7e14c9e026f..525d17c7612a7 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -1191,7 +1191,7 @@ def get_value(self, series, key): try: return self._engine.get_value(s, k) except KeyError as e1: - if len(self) > 0 and self.inferred_type == 'integer': + if len(self) > 0 and self.inferred_type in ['integer','boolean']: raise try: diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index 093954f1d8c1d..f4f8495b1dafd 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -123,6 +123,20 @@ def test_get(self): expected = 43 self.assertEqual(result,expected) + # GH 7407 + # with a boolean accessor + df = pd.DataFrame({'i':[0]*3, 'b':[False]*3}) + vc = df.i.value_counts() + result = vc.get(99,default='Missing') + self.assertEquals(result,'Missing') + + vc = df.b.value_counts() + result = vc.get(False,default='Missing') + self.assertEquals(result,3) + + result = vc.get(True,default='Missing') + self.assertEquals(result,'Missing') + def test_delitem(self): # GH 5542