Skip to content

Commit 3dd44f2

Browse files
author
Matt Wittmann
committed
BUG: TypeError in index coercion
1 parent 26782a9 commit 3dd44f2

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v0.18.1.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,5 @@ Bug Fixes
333333

334334

335335
- Bug in ``fill_value`` is ignored if the argument to a binary operator is a constant (:issue `12723`)
336+
337+
- Bug in index coercion when falling back from ```RangeIndex``` construction (:issue:`12893`)

pandas/indexes/multi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ def get_level_values(self, level):
666666
filled = algos.take_1d(unique.values, labels,
667667
fill_value=unique._na_value)
668668
_simple_new = unique._simple_new
669-
values = _simple_new(filled, self.names[num],
669+
values = _simple_new(filled, name=self.names[num],
670670
freq=getattr(unique, 'freq', None),
671671
tz=getattr(unique, 'tz', None))
672672
return values

pandas/tests/indexes/test_multi.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,3 +2130,12 @@ def test_partial_string_timestamp_multiindex(self):
21302130
# Slicing date on first level should break (of course)
21312131
with assertRaises(KeyError):
21322132
df_swap.loc['2016-01-01']
2133+
2134+
def test_rangeindex_fallback_coercion_bug(self):
2135+
# GH 12893
2136+
foo = pd.DataFrame(np.arange(100).reshape((10, 10)))
2137+
bar = pd.DataFrame(np.arange(100).reshape((10, 10)))
2138+
df = pd.concat({'foo': foo.stack(), 'bar': bar.stack()}, axis=1)
2139+
df.index.names = ['fizz', 'buzz']
2140+
expected = [i for i in range(10) for j in range(10)]
2141+
self.assertTrue((df.index.get_level_values('fizz') == expected).all())

0 commit comments

Comments
 (0)