Skip to content

Commit 822db7a

Browse files
TST: [ArrowStringArray] more parameterised testing - part 3 (#40755)
1 parent b5622c6 commit 822db7a

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

pandas/tests/io/formats/test_to_csv.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,17 @@ def test_to_csv_na_rep(self):
204204
assert df.set_index("a").to_csv(na_rep="_") == expected
205205
assert df.set_index(["a", "b"]).to_csv(na_rep="_") == expected
206206

207-
# GH 29975
208-
# Make sure full na_rep shows up when a dtype is provided
209207
csv = pd.Series(["a", pd.NA, "c"]).to_csv(na_rep="ZZZZZ")
210208
expected = tm.convert_rows_list_to_csv_str([",0", "0,a", "1,ZZZZZ", "2,c"])
211209
assert expected == csv
212-
csv = pd.Series(["a", pd.NA, "c"], dtype="string").to_csv(na_rep="ZZZZZ")
210+
211+
def test_to_csv_na_rep_nullable_string(self, nullable_string_dtype):
212+
# GH 29975
213+
# Make sure full na_rep shows up when a dtype is provided
214+
expected = tm.convert_rows_list_to_csv_str([",0", "0,a", "1,ZZZZZ", "2,c"])
215+
csv = pd.Series(["a", pd.NA, "c"], dtype=nullable_string_dtype).to_csv(
216+
na_rep="ZZZZZ"
217+
)
213218
assert expected == csv
214219

215220
def test_to_csv_date_format(self):

pandas/tests/io/test_parquet.py

+8
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,14 @@ def test_additional_extension_arrays(self, pa):
836836
expected = df.assign(a=df.a.astype("float64"))
837837
check_round_trip(df, pa, expected=expected)
838838

839+
@td.skip_if_no("pyarrow", min_version="1.0.0")
840+
def test_pyarrow_backed_string_array(self, pa):
841+
# test ArrowStringArray supported through the __arrow_array__ protocol
842+
from pandas.core.arrays.string_arrow import ArrowStringDtype # noqa: F401
843+
844+
df = pd.DataFrame({"a": pd.Series(["a", None, "c"], dtype="arrow_string")})
845+
check_round_trip(df, pa, expected=df)
846+
839847
@td.skip_if_no("pyarrow", min_version="0.16.0")
840848
def test_additional_extension_types(self, pa):
841849
# test additional ExtensionArrays that are supported through the

pandas/tests/series/methods/test_convert_dtypes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ def test_convert_dtypes(
212212
# Make sure original not changed
213213
tm.assert_series_equal(series, copy)
214214

215-
def test_convert_string_dtype(self):
215+
def test_convert_string_dtype(self, nullable_string_dtype):
216216
# https://github.com/pandas-dev/pandas/issues/31731 -> converting columns
217217
# that are already string dtype
218218
df = pd.DataFrame(
219-
{"A": ["a", "b", pd.NA], "B": ["ä", "ö", "ü"]}, dtype="string"
219+
{"A": ["a", "b", pd.NA], "B": ["ä", "ö", "ü"]}, dtype=nullable_string_dtype
220220
)
221221
result = df.convert_dtypes()
222222
tm.assert_frame_equal(df, result)

pandas/tests/series/methods/test_replace.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ def test_replace2(self):
254254
assert (ser[6:10] == -1).all()
255255
assert (ser[20:30] == -1).all()
256256

257-
def test_replace_with_dictlike_and_string_dtype(self):
257+
def test_replace_with_dictlike_and_string_dtype(self, nullable_string_dtype):
258258
# GH 32621
259-
s = pd.Series(["one", "two", np.nan], dtype="string")
259+
s = pd.Series(["one", "two", np.nan], dtype=nullable_string_dtype)
260260
expected = pd.Series(["1", "2", np.nan])
261261
result = s.replace({"one": "1", "two": "2"})
262262
tm.assert_series_equal(expected, result)

pandas/tests/series/test_constructors.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1549,10 +1549,12 @@ def test_constructor_datetime64(self):
15491549
series = Series(dates)
15501550
assert np.issubdtype(series.dtype, np.dtype("M8[ns]"))
15511551

1552-
def test_constructor_datetimelike_scalar_to_string_dtype(self):
1552+
def test_constructor_datetimelike_scalar_to_string_dtype(
1553+
self, nullable_string_dtype
1554+
):
15531555
# https://github.com/pandas-dev/pandas/pull/33846
1554-
result = Series("M", index=[1, 2, 3], dtype="string")
1555-
expected = Series(["M", "M", "M"], index=[1, 2, 3], dtype="string")
1556+
result = Series("M", index=[1, 2, 3], dtype=nullable_string_dtype)
1557+
expected = Series(["M", "M", "M"], index=[1, 2, 3], dtype=nullable_string_dtype)
15561558
tm.assert_series_equal(result, expected)
15571559

15581560
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)