-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
TEST: join df with categorical multiIndex #51088
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from pandas.core.dtypes.common import is_categorical_dtype | ||
|
||
import pandas as pd | ||
from pandas import ( | ||
Categorical, | ||
|
@@ -956,3 +958,27 @@ def test_join_empty(left_empty, how, exp): | |
expected = expected.rename_axis("A") | ||
|
||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_join_multiindex_categorical_output_index_dtype(): | ||
# GH#50906 | ||
df1 = DataFrame( | ||
{ | ||
"idx1": Categorical(["a", "a", "a"]), | ||
"idx2": Categorical(["a", "a", "b"]), | ||
"data": [1, 2, 3], | ||
} | ||
).set_index(["idx1", "idx2"]) | ||
|
||
df2 = DataFrame( | ||
{ | ||
"idx1": Categorical(["a", "a", "a"]), | ||
"idx2": Categorical(["a", "b", "b"]), | ||
"data2": [1, 2, 3], | ||
} | ||
).set_index(["idx1", "idx2"]) | ||
|
||
for how in ["inner", "outer", "left", "right"]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, of course. Added parametrize to this commit |
||
df = df1.join(df2, how=how) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you name this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you @mroeschke. I corrected the test as you suggested. |
||
assert is_categorical_dtype(df.index.levels[0]) is True | ||
assert is_categorical_dtype(df.index.levels[1]) is True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for working on this
why not use the example from #50906? for regression tests, if the original example is small and self-contained, it'd probably be safer to just use that directly
the rest looks good though 👍