Skip to content

Commit 2141c1c

Browse files
authored
CLN: Add tets and fix docstring for concat with sort=True and outer join (pandas-dev#47612)
Add tets and fix docstring
1 parent f654176 commit 2141c1c

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

pandas/core/indexes/api.py

+1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ def _unique_indices(inds, dtype) -> Index:
233233
Parameters
234234
----------
235235
inds : list of Index or list objects
236+
dtype : dtype to set for the resulting Index
236237
237238
Returns
238239
-------

pandas/tests/reshape/concat/test_index.py

+27-4
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,36 @@ def test_concat_range_index_result(self):
399399
expected_index = pd.RangeIndex(0, 2)
400400
tm.assert_index_equal(result.index, expected_index, exact=True)
401401

402-
@pytest.mark.parametrize("dtype", ["Int64", "object"])
403-
def test_concat_index_keep_dtype(self, dtype):
402+
def test_concat_index_keep_dtype(self):
403+
# GH#47329
404+
df1 = DataFrame([[0, 1, 1]], columns=Index([1, 2, 3], dtype="object"))
405+
df2 = DataFrame([[0, 1]], columns=Index([1, 2], dtype="object"))
406+
result = concat([df1, df2], ignore_index=True, join="outer", sort=True)
407+
expected = DataFrame(
408+
[[0, 1, 1.0], [0, 1, np.nan]], columns=Index([1, 2, 3], dtype="object")
409+
)
410+
tm.assert_frame_equal(result, expected)
411+
412+
def test_concat_index_keep_dtype_ea_numeric(self, any_numeric_ea_dtype):
413+
# GH#47329
414+
df1 = DataFrame(
415+
[[0, 1, 1]], columns=Index([1, 2, 3], dtype=any_numeric_ea_dtype)
416+
)
417+
df2 = DataFrame([[0, 1]], columns=Index([1, 2], dtype=any_numeric_ea_dtype))
418+
result = concat([df1, df2], ignore_index=True, join="outer", sort=True)
419+
expected = DataFrame(
420+
[[0, 1, 1.0], [0, 1, np.nan]],
421+
columns=Index([1, 2, 3], dtype=any_numeric_ea_dtype),
422+
)
423+
tm.assert_frame_equal(result, expected)
424+
425+
@pytest.mark.parametrize("dtype", ["Int8", "Int16", "Int32"])
426+
def test_concat_index_find_common(self, dtype):
404427
# GH#47329
405428
df1 = DataFrame([[0, 1, 1]], columns=Index([1, 2, 3], dtype=dtype))
406-
df2 = DataFrame([[0, 1]], columns=Index([1, 2], dtype=dtype))
429+
df2 = DataFrame([[0, 1]], columns=Index([1, 2], dtype="Int32"))
407430
result = concat([df1, df2], ignore_index=True, join="outer", sort=True)
408431
expected = DataFrame(
409-
[[0, 1, 1.0], [0, 1, np.nan]], columns=Index([1, 2, 3], dtype=dtype)
432+
[[0, 1, 1.0], [0, 1, np.nan]], columns=Index([1, 2, 3], dtype="Int32")
410433
)
411434
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)