Skip to content

Commit 5e79659

Browse files
author
Nicholas Musolino
committed
TST: Add test of DataFrame.xs() with duplicates (pandas-dev#13719)
1 parent 114f415 commit 5e79659

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pandas/tests/test_multilevel.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111

1212
from pandas.core.index import Index, MultiIndex
13-
from pandas import Panel, DataFrame, Series, notna, isna, Timestamp
13+
from pandas import Panel, DataFrame, Series, notna, isna, Timestamp, concat
1414

1515
from pandas.core.dtypes.common import is_float_dtype, is_integer_dtype
1616
import pandas.core.common as com
@@ -486,6 +486,13 @@ def test_xs_partial(self):
486486
expected = df.loc['foo', 'one']
487487
tm.assert_frame_equal(result, expected)
488488

489+
# DataFrame with a MultiIndex containing duplicates (#13719)
490+
df_dup = concat([self.frame] * 2)
491+
assert not df_dup.index.is_unique
492+
expected = concat([self.frame.xs('one', level='second')] * 2)
493+
tm.assert_frame_equal(df_dup.xs('one', level='second'), expected)
494+
tm.assert_frame_equal(df_dup.xs(['one'], level=['second']), expected)
495+
489496
def test_xs_level(self):
490497
result = self.frame.xs('two', level='second')
491498
expected = self.frame[self.frame.index.get_level_values(1) == 'two']

0 commit comments

Comments
 (0)