Skip to content

Commit ad11979

Browse files
simonjayhawkinsJulianWgs
authored andcommitted
TST: [ArrowStringArray] more parameterised testing - part 1 (pandas-dev#40679)
1 parent f3f0d50 commit ad11979

File tree

6 files changed

+35
-11
lines changed

6 files changed

+35
-11
lines changed

pandas/conftest.py

+18
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,24 @@ def string_dtype(request):
11311131
return request.param
11321132

11331133

1134+
@pytest.fixture(
1135+
params=[
1136+
"string",
1137+
pytest.param(
1138+
"arrow_string", marks=td.skip_if_no("pyarrow", min_version="1.0.0")
1139+
),
1140+
]
1141+
)
1142+
def nullable_string_dtype(request):
1143+
"""
1144+
Parametrized fixture for string dtypes.
1145+
1146+
* 'string'
1147+
* 'arrow_string'
1148+
"""
1149+
return request.param
1150+
1151+
11341152
@pytest.fixture(params=tm.BYTES_DTYPES)
11351153
def bytes_dtype(request):
11361154
"""

pandas/tests/dtypes/test_common.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,10 @@ def test_is_string_dtype():
281281
assert com.is_string_dtype(object)
282282
assert com.is_string_dtype(np.array(["a", "b"]))
283283
assert com.is_string_dtype(pd.StringDtype())
284-
assert com.is_string_dtype(pd.array(["a", "b"], dtype="string"))
284+
285+
286+
def test_is_string_dtype_nullable(nullable_string_dtype):
287+
assert com.is_string_dtype(pd.array(["a", "b"], dtype=nullable_string_dtype))
285288

286289

287290
integer_dtypes: List = []

pandas/tests/extension/json/array.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
ExtensionDtype,
4040
)
4141
from pandas.api.types import is_bool_dtype
42+
from pandas.core.arrays.string_arrow import ArrowStringDtype
4243

4344

4445
class JSONDtype(ExtensionDtype):
@@ -194,7 +195,7 @@ def astype(self, dtype, copy=True):
194195
if copy:
195196
return self.copy()
196197
return self
197-
elif isinstance(dtype, StringDtype):
198+
elif isinstance(dtype, (StringDtype, ArrowStringDtype)):
198199
value = self.astype(str) # numpy doesn'y like nested dicts
199200
return dtype.construct_array_type()._from_sequence(value, copy=False)
200201

pandas/tests/frame/methods/test_combine_first.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,17 @@ def test_combine_first_with_asymmetric_other(self, val):
381381

382382
tm.assert_frame_equal(res, exp)
383383

384-
def test_combine_first_string_dtype_only_na(self):
384+
def test_combine_first_string_dtype_only_na(self, nullable_string_dtype):
385385
# GH: 37519
386-
df = DataFrame({"a": ["962", "85"], "b": [pd.NA] * 2}, dtype="string")
387-
df2 = DataFrame({"a": ["85"], "b": [pd.NA]}, dtype="string")
386+
df = DataFrame(
387+
{"a": ["962", "85"], "b": [pd.NA] * 2}, dtype=nullable_string_dtype
388+
)
389+
df2 = DataFrame({"a": ["85"], "b": [pd.NA]}, dtype=nullable_string_dtype)
388390
df.set_index(["a", "b"], inplace=True)
389391
df2.set_index(["a", "b"], inplace=True)
390392
result = df.combine_first(df2)
391393
expected = DataFrame(
392-
{"a": ["962", "85"], "b": [pd.NA] * 2}, dtype="string"
394+
{"a": ["962", "85"], "b": [pd.NA] * 2}, dtype=nullable_string_dtype
393395
).set_index(["a", "b"])
394396
tm.assert_frame_equal(result, expected)
395397

pandas/tests/frame/test_constructors.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1654,10 +1654,10 @@ def test_constructor_empty_with_string_dtype(self):
16541654
df = DataFrame(index=[0, 1], columns=[0, 1], dtype="U5")
16551655
tm.assert_frame_equal(df, expected)
16561656

1657-
def test_constructor_empty_with_string_extension(self):
1657+
def test_constructor_empty_with_string_extension(self, nullable_string_dtype):
16581658
# GH 34915
1659-
expected = DataFrame(index=[], columns=["c1"], dtype="string")
1660-
df = DataFrame(columns=["c1"], dtype="string")
1659+
expected = DataFrame(index=[], columns=["c1"], dtype=nullable_string_dtype)
1660+
df = DataFrame(columns=["c1"], dtype=nullable_string_dtype)
16611661
tm.assert_frame_equal(df, expected)
16621662

16631663
def test_constructor_single_value(self):

pandas/tests/tools/test_to_numeric.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,9 @@ def test_precision_float_conversion(strrep):
725725
(["1", "2", "3.5"], Series([1, 2, 3.5])),
726726
],
727727
)
728-
def test_to_numeric_from_nullable_string(values, expected):
728+
def test_to_numeric_from_nullable_string(values, nullable_string_dtype, expected):
729729
# https://github.com/pandas-dev/pandas/issues/37262
730-
s = Series(values, dtype="string")
730+
s = Series(values, dtype=nullable_string_dtype)
731731
result = to_numeric(s)
732732
tm.assert_series_equal(result, expected)
733733

0 commit comments

Comments
 (0)