Skip to content

Commit 2ed994f

Browse files
authored
Adjust tests in dtypes folder for arrow string option (#56125)
Adjust tests in base folder for arrow string option
1 parent 8ba1ab0 commit 2ed994f

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

pandas/tests/computation/test_eval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ def test_bool_ops_fails_on_scalars(lhs, cmp, rhs, engine, parser):
18321832
],
18331833
)
18341834
def test_equals_various(other):
1835-
df = DataFrame({"A": ["a", "b", "c"]})
1835+
df = DataFrame({"A": ["a", "b", "c"]}, dtype=object)
18361836
result = df.eval(f"A == {other}")
18371837
expected = Series([False, False, False], name="A")
18381838
if USE_NUMEXPR:

pandas/tests/dtypes/cast/test_construct_ndarray.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import pytest
33

4+
import pandas as pd
45
import pandas._testing as tm
56
from pandas.core.construction import sanitize_array
67

@@ -15,9 +16,14 @@
1516
([1, 2, None], np.dtype("str"), np.array(["1", "2", None])),
1617
],
1718
)
18-
def test_construct_1d_ndarray_preserving_na(values, dtype, expected):
19+
def test_construct_1d_ndarray_preserving_na(
20+
values, dtype, expected, using_infer_string
21+
):
1922
result = sanitize_array(values, index=None, dtype=dtype)
20-
tm.assert_numpy_array_equal(result, expected)
23+
if using_infer_string and expected.dtype == object and dtype is None:
24+
tm.assert_extension_array_equal(result, pd.array(expected))
25+
else:
26+
tm.assert_numpy_array_equal(result, expected)
2127

2228

2329
@pytest.mark.parametrize("dtype", ["m8[ns]", "M8[ns]"])

pandas/tests/dtypes/cast/test_infer_dtype.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ def test_infer_dtype_from_scalar_errors():
159159
(Timestamp("20160101", tz="UTC"), "datetime64[s, UTC]"),
160160
],
161161
)
162-
def test_infer_dtype_from_scalar(value, expected):
162+
def test_infer_dtype_from_scalar(value, expected, using_infer_string):
163163
dtype, _ = infer_dtype_from_scalar(value)
164+
if using_infer_string and value == "foo":
165+
expected = "string"
164166
assert is_dtype_equal(dtype, expected)
165167

166168
with pytest.raises(TypeError, match="must be list-like"):
@@ -189,8 +191,14 @@ def test_infer_dtype_from_scalar(value, expected):
189191
),
190192
],
191193
)
192-
def test_infer_dtype_from_array(arr, expected):
194+
def test_infer_dtype_from_array(arr, expected, using_infer_string):
193195
dtype, _ = infer_dtype_from_array(arr)
196+
if (
197+
using_infer_string
198+
and isinstance(arr, Series)
199+
and arr.tolist() == ["a", "b", "c"]
200+
):
201+
expected = "string"
194202
assert is_dtype_equal(dtype, expected)
195203

196204

pandas/tests/dtypes/test_common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,9 @@ def test_is_complex_dtype():
676676
(np.dtype("float64"), np.dtype("float64")),
677677
(str, np.dtype(str)),
678678
(pd.Series([1, 2], dtype=np.dtype("int16")), np.dtype("int16")),
679-
(pd.Series(["a", "b"]), np.dtype(object)),
679+
(pd.Series(["a", "b"], dtype=object), np.dtype(object)),
680680
(pd.Index([1, 2]), np.dtype("int64")),
681-
(pd.Index(["a", "b"]), np.dtype(object)),
681+
(pd.Index(["a", "b"], dtype=object), np.dtype(object)),
682682
("category", "category"),
683683
(pd.Categorical(["a", "b"]).dtype, CategoricalDtype(["a", "b"])),
684684
(pd.Categorical(["a", "b"]), CategoricalDtype(["a", "b"])),
@@ -727,9 +727,9 @@ def test_get_dtype_fails(input_param, expected_error_message):
727727
(np.dtype("float64"), np.float64),
728728
(str, np.dtype(str).type),
729729
(pd.Series([1, 2], dtype=np.dtype("int16")), np.int16),
730-
(pd.Series(["a", "b"]), np.object_),
730+
(pd.Series(["a", "b"], dtype=object), np.object_),
731731
(pd.Index([1, 2], dtype="int64"), np.int64),
732-
(pd.Index(["a", "b"]), np.object_),
732+
(pd.Index(["a", "b"], dtype=object), np.object_),
733733
("category", CategoricalDtypeType),
734734
(pd.Categorical(["a", "b"]).dtype, CategoricalDtypeType),
735735
(pd.Categorical(["a", "b"]), CategoricalDtypeType),

pandas/tests/dtypes/test_dtypes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,13 +1055,14 @@ def test_from_categorical_dtype_both(self):
10551055
)
10561056
assert result == CategoricalDtype([1, 2], ordered=False)
10571057

1058-
def test_str_vs_repr(self, ordered):
1058+
def test_str_vs_repr(self, ordered, using_infer_string):
10591059
c1 = CategoricalDtype(["a", "b"], ordered=ordered)
10601060
assert str(c1) == "category"
10611061
# Py2 will have unicode prefixes
1062+
dtype = "string" if using_infer_string else "object"
10621063
pat = (
10631064
r"CategoricalDtype\(categories=\[.*\], ordered={ordered}, "
1064-
r"categories_dtype=object\)"
1065+
rf"categories_dtype={dtype}\)"
10651066
)
10661067
assert re.match(pat.format(ordered=ordered), repr(c1))
10671068

0 commit comments

Comments
 (0)