-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: pd.concat produces frames with inconsistent order when concating the ones with categorical indices #46019
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 18 commits
79b00aa
f88c5ab
0b95cbc
a75ea1f
1198c2a
ea67938
7a02b94
eaee6aa
40a9d88
10a08a6
5d3f048
b8f5c0e
a66a60f
ffeaee0
d802962
fc1eb01
74ff83f
aacc75c
91d2155
3425b85
094204c
91c5335
99dcc08
0e62a36
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 |
---|---|---|
|
@@ -286,6 +286,17 @@ def test_map_str(self): | |
# See test_map.py | ||
pass | ||
|
||
def test_append(self): | ||
# GH 44099 | ||
# concat indexes which have the same categories | ||
|
||
ci1 = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"]) | ||
ci2 = CategoricalIndex(["b", "a", "c"], categories=["b", "a", "c"]) | ||
expected = CategoricalIndex( | ||
["a", "b", "c", "b", "a", "c"], categories=["a", "b", "c"] | ||
) | ||
tm.assert_index_equal(ci1.append(ci2), expected) | ||
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. 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. I also changed at this commit 91d2155 |
||
|
||
|
||
class TestCategoricalIndex2: | ||
# Tests that are not overriding a test in Base | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
import pandas as pd | ||
from pandas import ( | ||
CategoricalIndex, | ||
DataFrame, | ||
Index, | ||
MultiIndex, | ||
|
@@ -502,6 +503,26 @@ def test_concat_duplicate_indices_raise(self): | |
with pytest.raises(InvalidIndexError, match=msg): | ||
concat([df1, df2], axis=1) | ||
|
||
def test_concat_with_categorical_indices(self): | ||
# GH 44099 | ||
# concat frames with categorical indices that have the same values | ||
|
||
df1 = DataFrame( | ||
{"col1": ["a_val", "b_val", "c_val"]}, | ||
index=CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"]), | ||
) | ||
df2 = DataFrame( | ||
{"col1": ["b_val", "a_val", "c_val"]}, | ||
index=CategoricalIndex(["b", "a", "c"], categories=["b", "a", "c"]), | ||
) | ||
expected = DataFrame( | ||
{"col1": ["a_val", "b_val", "c_val", "b_val", "a_val", "c_val"]}, | ||
index=CategoricalIndex( | ||
["a", "b", "c", "b", "a", "c"], categories=["a", "b", "c"] | ||
), | ||
) | ||
tm.assert_frame_equal(concat([df1, df2]), expected) | ||
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. 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. Thanks! I changed at this commit 91d2155 |
||
|
||
|
||
@pytest.mark.parametrize("pdt", [Series, DataFrame]) | ||
@pytest.mark.parametrize("dt", np.sctypes["float"]) | ||
|
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.
can you update the note here; this should be about the user facing case in the OP
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! I added description line at
reshaping
section that refer toconcat
func in this commit 3425b85Is this the correct fix that you pointed out?
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.
@jreback Hi! Thanks for all your reviews.
I would like to request a review from you again.
I finally change doc/source/whatsnew/v1.5.0.rst in this commit(0e62a36)