Skip to content

TST: test loc index df with a MultiIndex and constituent IntervalIndex #52811

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

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 13 additions & 0 deletions pandas/tests/indexing/multiindex/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,3 +971,16 @@ def test_multindex_series_loc_with_tuple_label():
ser = Series([1, 2], index=mi)
result = ser.loc[(3, (4, 5))]
assert result == 2

def test_loc_multiindex_and_intervalindex():
#https://github.com/pandas-dev/pandas/issues/25298
#test to index the dataframe with a MultiIndex and IntervalIndex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove all comments except the link to the GitHub issue


#create an IntervalIndex
ii = pd.IntervalIndex.from_arrays([1, 5, 2, 6, 3, 7], [4, 8, 5, 9, 6, 10])
#create a MultiIndex using the IntervalIndex and an array of strings
mi = pd.MultiIndex.from_arrays([["aa", "aa", "bb", "bb", "cc", "cc"], ii])
data = [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10), (11, 12)]
df = pd.DataFrame(data, columns=['k', 'l'], index=mi)
result = pd.DataFrame({'k': [5], 'l': [6]}, index=pd.MultiIndex.from_tuples([('bb', pd.Interval(2, 5))], names=[None, None]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you run pre-commit? This line is too long

assert result.equals(df.loc[("bb", 3)])