From 2b7755419c7e5140cbe70f935ad78d87f3d0b6c1 Mon Sep 17 00:00:00 2001 From: Ben Kandel Date: Fri, 26 Aug 2016 14:09:01 -0400 Subject: [PATCH] Fix bug in Float64Index.get_value() for tuples. Currently, trying to retrieve one tuple-valued entry in a Series with a Float64Index will fail (GH 13509). This fixes that bug. --- doc/source/whatsnew/v0.19.0.txt | 1 + pandas/indexes/numeric.py | 10 +--------- pandas/tests/indexing/test_floats.py | 5 +++++ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/doc/source/whatsnew/v0.19.0.txt b/doc/source/whatsnew/v0.19.0.txt index 2811e31128156..99f1a89fe233a 100644 --- a/doc/source/whatsnew/v0.19.0.txt +++ b/doc/source/whatsnew/v0.19.0.txt @@ -1253,3 +1253,4 @@ Bug Fixes - Bug in ``.to_string()`` when called with an integer ``line_width`` and ``index=False`` raises an UnboundLocalError exception because ``idx`` referenced before assignment. - Bug in ``read_csv()``, where aliases for utf-xx (e.g. UTF-xx, UTF_xx, utf_xx) raised UnicodeDecodeError (:issue:`13549`) +- Bug in ``Float64Index.get_value()`` where trying to access one tuple-valued entry in a ``Series`` failed (:issue:`13509`) diff --git a/pandas/indexes/numeric.py b/pandas/indexes/numeric.py index 82a6ec0b28ac9..e1ac0939812f6 100644 --- a/pandas/indexes/numeric.py +++ b/pandas/indexes/numeric.py @@ -293,19 +293,11 @@ def get_value(self, series, key): if not is_scalar(key): raise InvalidIndexError - from pandas.core.indexing import maybe_droplevels - from pandas.core.series import Series - k = _values_from_object(key) loc = self.get_loc(k) new_values = _values_from_object(series)[loc] - if is_scalar(new_values) or new_values is None: - return new_values - - new_index = self[loc] - new_index = maybe_droplevels(new_index, k) - return Series(new_values, index=new_index, name=series.name) + return new_values def equals(self, other): """ diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index 29f3889d20bd0..3e9f7631e2de7 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -676,3 +676,8 @@ def test_floating_misc(self): assert_series_equal(result1, result2) assert_series_equal(result1, result3) assert_series_equal(result1, Series([1], index=[2.5])) + + def test_floating_tuples(self): + s = Series([(1, 1), (2, 2), (3, 3)], index=[0.0, 0.1, 0.2]) + result = s[0.0] + assert result == (1, 1)