Skip to content

Commit 75df622

Browse files
zhengfeiwangphofl
authored andcommitted
TST: add test for DataFrame with duplicate indices concat (pandas-dev#45888)
* add test for DataFrame.join() DataFrame.join() with duplicate indices should raise now and add test for this. * Update test_join.py catch concat's raise, not join * Fixes from pre-commit [automated commit] * Update test_join.py add msg for pytest.raises for Code Check * move new test to concat * Update test_concat.py remove whitespace in blank line * Fixes from pre-commit [automated commit] * Update test_concat.py add detailed description for test, also tend to trigger all checks * Update test_concat.py use concat directly instead of pd.concat for flake8
1 parent 2fabac7 commit 75df622

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pandas/tests/reshape/concat/test_concat.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import numpy as np
1212
import pytest
1313

14-
from pandas.errors import PerformanceWarning
14+
from pandas.errors import (
15+
InvalidIndexError,
16+
PerformanceWarning,
17+
)
1518

1619
import pandas as pd
1720
from pandas import (
@@ -490,6 +493,15 @@ def test_concat_ordered_dict(self):
490493
result = concat({"First": Series(range(3)), "Another": Series(range(4))})
491494
tm.assert_series_equal(result, expected)
492495

496+
def test_concat_duplicate_indices_raise(self):
497+
# GH 45888: test raise for concat DataFrames with duplicate indices
498+
# https://github.com/pandas-dev/pandas/issues/36263
499+
df1 = DataFrame(np.random.randn(5), index=[0, 1, 2, 3, 3], columns=["a"])
500+
df2 = DataFrame(np.random.randn(5), index=[0, 1, 2, 2, 4], columns=["b"])
501+
msg = "Reindexing only valid with uniquely valued Index objects"
502+
with pytest.raises(InvalidIndexError, match=msg):
503+
concat([df1, df2], axis=1)
504+
493505

494506
@pytest.mark.parametrize("pdt", [Series, DataFrame])
495507
@pytest.mark.parametrize("dt", np.sctypes["float"])

0 commit comments

Comments
 (0)