Skip to content

TST: Add test of DataFrame.xs() with duplicates (#13719) #22294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import numpy as np

from pandas.core.index import Index, MultiIndex
from pandas import Panel, DataFrame, Series, notna, isna, Timestamp, read_csv
from pandas import (Panel, DataFrame, Series, notna, isna, Timestamp, concat,
read_csv)

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

def test_xs_with_duplicates(self):
# Issue #13719
df_dup = concat([self.frame] * 2)
assert not df_dup.index.is_unique
expected = concat([self.frame.xs('one', level='second')] * 2)
tm.assert_frame_equal(df_dup.xs('one', level='second'), expected)
tm.assert_frame_equal(df_dup.xs(['one'], level=['second']), expected)

def test_xs_level(self):
result = self.frame.xs('two', level='second')
expected = self.frame[self.frame.index.get_level_values(1) == 'two']
Expand Down