Skip to content

Commit 224ea88

Browse files
authored
Adjust concat tests for string option (pandas-dev#56446)
1 parent 0dd6954 commit 224ea88

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

pandas/tests/reshape/concat/test_append_common.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ class TestConcatAppendCommon:
5757
Test common dtype coercion rules between concat and append.
5858
"""
5959

60-
def test_dtypes(self, item, index_or_series):
60+
def test_dtypes(self, item, index_or_series, using_infer_string):
6161
# to confirm test case covers intended dtypes
6262
typ, vals = item
6363
obj = index_or_series(vals)
64+
if typ == "object" and using_infer_string:
65+
typ = "string"
6466
if isinstance(obj, Index):
6567
assert obj.dtype == typ
6668
elif isinstance(obj, Series):

pandas/tests/reshape/concat/test_categorical.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@ def test_categorical_concat(self, sort):
5151
exp["h"] = exp["h"].astype(df2["h"].dtype)
5252
tm.assert_frame_equal(res, exp)
5353

54-
def test_categorical_concat_dtypes(self):
54+
def test_categorical_concat_dtypes(self, using_infer_string):
5555
# GH8143
5656
index = ["cat", "obj", "num"]
5757
cat = Categorical(["a", "b", "c"])
5858
obj = Series(["a", "b", "c"])
5959
num = Series([1, 2, 3])
6060
df = pd.concat([Series(cat), obj, num], axis=1, keys=index)
6161

62-
result = df.dtypes == "object"
62+
result = df.dtypes == (
63+
object if not using_infer_string else "string[pyarrow_numpy]"
64+
)
6365
expected = Series([False, True, False], index=index)
6466
tm.assert_series_equal(result, expected)
6567

pandas/tests/reshape/concat/test_empty.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
class TestEmptyConcat:
16-
def test_handle_empty_objects(self, sort):
16+
def test_handle_empty_objects(self, sort, using_infer_string):
1717
df = DataFrame(
1818
np.random.default_rng(2).standard_normal((10, 4)), columns=list("abcd")
1919
)
@@ -26,7 +26,9 @@ def test_handle_empty_objects(self, sort):
2626
concatted = concat(frames, axis=0, sort=sort)
2727

2828
expected = df.reindex(columns=["a", "b", "c", "d", "foo"])
29-
expected["foo"] = expected["foo"].astype("O")
29+
expected["foo"] = expected["foo"].astype(
30+
object if not using_infer_string else "string[pyarrow_numpy]"
31+
)
3032
expected.loc[0:4, "foo"] = "bar"
3133

3234
tm.assert_frame_equal(concatted, expected)
@@ -275,14 +277,14 @@ def test_concat_empty_dataframe(self):
275277
expected = DataFrame(columns=["a", "b"])
276278
tm.assert_frame_equal(result, expected)
277279

278-
def test_concat_empty_dataframe_different_dtypes(self):
280+
def test_concat_empty_dataframe_different_dtypes(self, using_infer_string):
279281
# 39037
280282
df1 = DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]})
281283
df2 = DataFrame({"a": [1, 2, 3]})
282284

283285
result = concat([df1[:0], df2[:0]])
284286
assert result["a"].dtype == np.int64
285-
assert result["b"].dtype == np.object_
287+
assert result["b"].dtype == np.object_ if not using_infer_string else "string"
286288

287289
def test_concat_to_empty_ea(self):
288290
"""48510 `concat` to an empty EA should maintain type EA dtype."""

pandas/tests/reshape/concat/test_index.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,14 @@ def test_concat_index_find_common(self, dtype):
447447
)
448448
tm.assert_frame_equal(result, expected)
449449

450-
def test_concat_axis_1_sort_false_rangeindex(self):
450+
def test_concat_axis_1_sort_false_rangeindex(self, using_infer_string):
451451
# GH 46675
452452
s1 = Series(["a", "b", "c"])
453453
s2 = Series(["a", "b"])
454454
s3 = Series(["a", "b", "c", "d"])
455-
s4 = Series([], dtype=object)
455+
s4 = Series(
456+
[], dtype=object if not using_infer_string else "string[pyarrow_numpy]"
457+
)
456458
result = concat(
457459
[s1, s2, s3, s4], sort=False, join="outer", ignore_index=False, axis=1
458460
)
@@ -463,7 +465,7 @@ def test_concat_axis_1_sort_false_rangeindex(self):
463465
["c", np.nan] * 2,
464466
[np.nan] * 2 + ["d"] + [np.nan],
465467
],
466-
dtype=object,
468+
dtype=object if not using_infer_string else "string[pyarrow_numpy]",
467469
)
468470
tm.assert_frame_equal(
469471
result, expected, check_index_type=True, check_column_type=True

0 commit comments

Comments
 (0)