Skip to content

BUG: pd.concat with identical key leads to multi-indexing error #46546

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 16 commits into from
Apr 5, 2022
Prev Previous commit
fix format
  • Loading branch information
GYHHAHA authored Apr 4, 2022
commit 330187bda3e05cde366819437b828cbffe67e48a
12 changes: 4 additions & 8 deletions pandas/tests/reshape/concat/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,15 @@ def test_concat_with_key_not_unique(self):
df_a = concat([df1, df2, df3], keys=["x", "y", "x"])
# the warning is caused by indexing unsorted multi-index
with tm.assert_produces_warning(
PerformanceWarning,
match="indexing past lexsort depth"
PerformanceWarning, match="indexing past lexsort depth"
):
out_a = df_a.loc[("x", 0), :]

df_b = DataFrame(
{"name": [1, 2, 3]}, index=Index([("x", 0), ("y", 0), ("x", 0)])
)
with tm.assert_produces_warning(
PerformanceWarning,
match="indexing past lexsort depth"
PerformanceWarning, match="indexing past lexsort depth"
):
out_b = df_b.loc[("x", 0)]

Expand All @@ -355,8 +353,7 @@ def test_concat_with_key_not_unique(self):
df3 = DataFrame({"name": ["c", "d"]})
df_a = concat([df1, df2, df3], keys=["x", "y", "x"])
with tm.assert_produces_warning(
PerformanceWarning,
match="indexing past lexsort depth"
PerformanceWarning, match="indexing past lexsort depth"
):
out_a = df_a.loc[("x", 0), :]

Expand All @@ -369,8 +366,7 @@ def test_concat_with_key_not_unique(self):
).set_index(["a", "b"])
df_b.index.names = [None, None]
with tm.assert_produces_warning(
PerformanceWarning,
match="indexing past lexsort depth"
PerformanceWarning, match="indexing past lexsort depth"
):
out_b = df_b.loc[("x", 0), :]

Expand Down