Skip to content

Commit 2b81853

Browse files
nmusolinoaeltanawy
authored andcommitted
TST: Add test of DataFrame.xs() with duplicates (pandas-dev#13719) (pandas-dev#22294)
1 parent 831a527 commit 2b81853

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pandas/tests/test_multilevel.py

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

1212
from pandas.core.index import Index, MultiIndex
13-
from pandas import Panel, DataFrame, Series, notna, isna, Timestamp, read_csv
13+
from pandas import (Panel, DataFrame, Series, notna, isna, Timestamp, concat,
14+
read_csv)
1415

1516
from pandas.core.dtypes.common import is_float_dtype, is_integer_dtype
1617
import pandas.core.common as com
@@ -486,6 +487,14 @@ def test_xs_partial(self):
486487
expected = df.loc['foo', 'one']
487488
tm.assert_frame_equal(result, expected)
488489

490+
def test_xs_with_duplicates(self):
491+
# Issue #13719
492+
df_dup = concat([self.frame] * 2)
493+
assert not df_dup.index.is_unique
494+
expected = concat([self.frame.xs('one', level='second')] * 2)
495+
tm.assert_frame_equal(df_dup.xs('one', level='second'), expected)
496+
tm.assert_frame_equal(df_dup.xs(['one'], level=['second']), expected)
497+
489498
def test_xs_level(self):
490499
result = self.frame.xs('two', level='second')
491500
expected = self.frame[self.frame.index.get_level_values(1) == 'two']

0 commit comments

Comments
 (0)