Skip to content

Commit e31f981

Browse files
Ben Kandeljreback
Ben Kandel
authored andcommitted
BUG: Series indexing with tuple-valued data and a numeric index
closes pandas-dev#13509 Author: Ben Kandel <[email protected]> Closes pandas-dev#14092 from bkandel/fix-floatindex-tuple and squashes the following commits: 2b77554 [Ben Kandel] Fix bug in Float64Index.get_value() for tuples.
1 parent 042b6f0 commit e31f981

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

doc/source/whatsnew/v0.19.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,7 @@ Bug Fixes
11501150
- Bug in ``DatetimeTZDtype`` dtype with ``dateutil.tz.tzlocal`` cannot be regarded as valid dtype (:issue:`13583`)
11511151
- Bug in ``pd.read_hdf()`` where attempting to load an HDF file with a single dataset, that had one or more categorical columns, failed unless the key argument was set to the name of the dataset. (:issue:`13231`)
11521152
- Bug in ``.rolling()`` that allowed a negative integer window in contruction of the ``Rolling()`` object, but would later fail on aggregation (:issue:`13383`)
1153+
- Bug in ``Series`` indexing with tuple-valued data and a numeric index (:issue:`13509`)
11531154

11541155
- Bug in printing ``pd.DataFrame`` where unusual elements with the ``object`` dtype were causing segfaults (:issue:`13717`)
11551156
- Bug in ranking ``Series`` which could result in segfaults (:issue:`13445`)

pandas/indexes/numeric.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -293,19 +293,11 @@ def get_value(self, series, key):
293293
if not is_scalar(key):
294294
raise InvalidIndexError
295295

296-
from pandas.core.indexing import maybe_droplevels
297-
from pandas.core.series import Series
298-
299296
k = _values_from_object(key)
300297
loc = self.get_loc(k)
301298
new_values = _values_from_object(series)[loc]
302299

303-
if is_scalar(new_values) or new_values is None:
304-
return new_values
305-
306-
new_index = self[loc]
307-
new_index = maybe_droplevels(new_index, k)
308-
return Series(new_values, index=new_index, name=series.name)
300+
return new_values
309301

310302
def equals(self, other):
311303
"""

pandas/tests/indexing/test_floats.py

+11
Original file line numberDiff line numberDiff line change
@@ -676,3 +676,14 @@ def test_floating_misc(self):
676676
assert_series_equal(result1, result2)
677677
assert_series_equal(result1, result3)
678678
assert_series_equal(result1, Series([1], index=[2.5]))
679+
680+
def test_floating_tuples(self):
681+
# GH13509
682+
s = Series([(1, 1), (2, 2), (3, 3)], index=[0.0, 0.1, 0.2], name='foo')
683+
result = s[0.0]
684+
self.assertEqual(result, (1, 1))
685+
686+
s = Series([(1, 1), (2, 2), (3, 3)], index=[0.0, 0.0, 0.2], name='foo')
687+
result = s[0.0]
688+
expected = Series([(1, 1), (2, 2)], index=[0.0, 0.0], name='foo')
689+
assert_series_equal(result, expected)

0 commit comments

Comments
 (0)