Skip to content

Commit 0774ecd

Browse files
phoflmroeschke
authored andcommitted
Improve error message for StringDtype with invalid storage (pandas-dev#55052)
1 parent 6acf643 commit 0774ecd

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pandas/core/arrays/string_.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def __init__(self, storage=None) -> None:
123123
storage = get_option("mode.string_storage")
124124
if storage not in {"python", "pyarrow", "pyarrow_numpy"}:
125125
raise ValueError(
126-
f"Storage must be 'python' or 'pyarrow'. Got {storage} instead."
126+
f"Storage must be 'python', 'pyarrow' or 'pyarrow_numpy'. "
127+
f"Got {storage} instead."
127128
)
128129
if storage in ("pyarrow", "pyarrow_numpy") and pa_version_under7p0:
129130
raise ImportError(

pandas/tests/arrays/string_/test_string_arrow.py

+8
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,11 @@ def test_pickle_roundtrip():
255255

256256
result_sliced = pickle.loads(sliced_pickled)
257257
tm.assert_series_equal(result_sliced, expected_sliced)
258+
259+
260+
@skip_if_no_pyarrow
261+
def test_string_dtype_error_message():
262+
# GH#55051
263+
msg = "Storage must be 'python', 'pyarrow' or 'pyarrow_numpy'."
264+
with pytest.raises(ValueError, match=msg):
265+
StringDtype("bla")

0 commit comments

Comments
 (0)