Skip to content
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

Adjust concat tests for string option #56446

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pandas/tests/reshape/concat/test_append_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ class TestConcatAppendCommon:
Test common dtype coercion rules between concat and append.
"""

def test_dtypes(self, item, index_or_series):
def test_dtypes(self, item, index_or_series, using_infer_string):
# to confirm test case covers intended dtypes
typ, vals = item
obj = index_or_series(vals)
if typ == "object" and using_infer_string:
typ = "string"
if isinstance(obj, Index):
assert obj.dtype == typ
elif isinstance(obj, Series):
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/reshape/concat/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ def test_categorical_concat(self, sort):
exp["h"] = exp["h"].astype(df2["h"].dtype)
tm.assert_frame_equal(res, exp)

def test_categorical_concat_dtypes(self):
def test_categorical_concat_dtypes(self, using_infer_string):
# GH8143
index = ["cat", "obj", "num"]
cat = Categorical(["a", "b", "c"])
obj = Series(["a", "b", "c"])
num = Series([1, 2, 3])
df = pd.concat([Series(cat), obj, num], axis=1, keys=index)

result = df.dtypes == "object"
result = df.dtypes == (
object if not using_infer_string else "string[pyarrow_numpy]"
)
expected = Series([False, True, False], index=index)
tm.assert_series_equal(result, expected)

Expand Down
10 changes: 6 additions & 4 deletions pandas/tests/reshape/concat/test_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


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

expected = df.reindex(columns=["a", "b", "c", "d", "foo"])
expected["foo"] = expected["foo"].astype("O")
expected["foo"] = expected["foo"].astype(
object if not using_infer_string else "string[pyarrow_numpy]"
)
expected.loc[0:4, "foo"] = "bar"

tm.assert_frame_equal(concatted, expected)
Expand Down Expand Up @@ -275,14 +277,14 @@ def test_concat_empty_dataframe(self):
expected = DataFrame(columns=["a", "b"])
tm.assert_frame_equal(result, expected)

def test_concat_empty_dataframe_different_dtypes(self):
def test_concat_empty_dataframe_different_dtypes(self, using_infer_string):
# 39037
df1 = DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]})
df2 = DataFrame({"a": [1, 2, 3]})

result = concat([df1[:0], df2[:0]])
assert result["a"].dtype == np.int64
assert result["b"].dtype == np.object_
assert result["b"].dtype == np.object_ if not using_infer_string else "string"

def test_concat_to_empty_ea(self):
"""48510 `concat` to an empty EA should maintain type EA dtype."""
Expand Down
8 changes: 5 additions & 3 deletions pandas/tests/reshape/concat/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,14 @@ def test_concat_index_find_common(self, dtype):
)
tm.assert_frame_equal(result, expected)

def test_concat_axis_1_sort_false_rangeindex(self):
def test_concat_axis_1_sort_false_rangeindex(self, using_infer_string):
# GH 46675
s1 = Series(["a", "b", "c"])
s2 = Series(["a", "b"])
s3 = Series(["a", "b", "c", "d"])
s4 = Series([], dtype=object)
s4 = Series(
[], dtype=object if not using_infer_string else "string[pyarrow_numpy]"
)
result = concat(
[s1, s2, s3, s4], sort=False, join="outer", ignore_index=False, axis=1
)
Expand All @@ -463,7 +465,7 @@ def test_concat_axis_1_sort_false_rangeindex(self):
["c", np.nan] * 2,
[np.nan] * 2 + ["d"] + [np.nan],
],
dtype=object,
dtype=object if not using_infer_string else "string[pyarrow_numpy]",
)
tm.assert_frame_equal(
result, expected, check_index_type=True, check_column_type=True
Expand Down