Skip to content

Commit 0479618

Browse files
committed
TST: add OP test, use fixture in the index test
1 parent fb3a906 commit 0479618

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

pandas/tests/indexes/test_common.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,16 @@ def test_astype_preserves_name(self, index, dtype, copy):
398398
assert result.name == index.name
399399

400400

401-
@pytest.mark.parametrize("exp_arr, sort", [([0, 1, 4, 3], False), ([0, 1, 3, 4], True)])
401+
@pytest.mark.parametrize("arr", [[0, 1, 4, 3]])
402402
@pytest.mark.parametrize("dtype", ["int8", "int16", "int32", "int64"])
403-
def test_union_index_no_sort(exp_arr, sort, dtype):
403+
def test_union_index_no_sort(arr, sort, dtype):
404404
# GH 35092. Check that we don't sort with sort=False
405-
ind1 = Index([0, 1], dtype=dtype)
406-
ind2 = Index([4, 3], dtype=dtype)
405+
ind1 = Index(arr[:2], dtype=dtype)
406+
ind2 = Index(arr[2:], dtype=dtype)
407407

408-
expected = Index(exp_arr, dtype=dtype)
408+
# sort is None indicates that we sort the combined index
409+
if sort is None:
410+
arr.sort()
411+
expected = Index(arr, dtype=dtype)
409412
result = union_indexes([ind1, ind2], sort=sort)
410413
tm.assert_index_equal(result, expected)

pandas/tests/reshape/test_concat.py

+14
Original file line numberDiff line numberDiff line change
@@ -2857,3 +2857,17 @@ def test_concat_frame_axis0_extension_dtypes():
28572857
result = pd.concat([df2, df1], ignore_index=True)
28582858
expected = pd.DataFrame({"a": [4, 5, 6, 1, 2, 3]}, dtype="Int64")
28592859
tm.assert_frame_equal(result, expected)
2860+
2861+
2862+
@pytest.mark.parametrize("sort", [True, False])
2863+
def test_append_sort(sort):
2864+
# GH 35092. Check that DataFrame.append respects the sort argument.
2865+
df1 = pd.DataFrame(data={0: [1,2], 1: [3,4]})
2866+
df2 = pd.DataFrame(data={3: [1,2], 2: [3,4]})
2867+
cols = list(df1.columns) + list(df2.columns)
2868+
if sort:
2869+
cols.sort()
2870+
2871+
result = df1.append(df2, sort=sort).columns
2872+
expected = type(result)(cols)
2873+
tm.assert_index_equal(result, expected)

0 commit comments

Comments
 (0)