Skip to content

Commit 77d29db

Browse files
Backport PR #55052 on branch 2.1.x (Improve error message for StringDtype with invalid storage) (#55053)
Backport PR #55052: Improve error message for StringDtype with invalid storage Co-authored-by: Patrick Hoefler <[email protected]>
1 parent 6db7b00 commit 77d29db

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pandas/core/arrays/string_.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ def __init__(self, storage=None) -> None:
119119
storage = get_option("mode.string_storage")
120120
if storage not in {"python", "pyarrow", "pyarrow_numpy"}:
121121
raise ValueError(
122-
f"Storage must be 'python' or 'pyarrow'. Got {storage} instead."
122+
f"Storage must be 'python', 'pyarrow' or 'pyarrow_numpy'. "
123+
f"Got {storage} instead."
123124
)
124125
if storage in ("pyarrow", "pyarrow_numpy") and pa_version_under7p0:
125126
raise ImportError(

pandas/tests/arrays/string_/test_string_arrow.py

Lines changed: 8 additions & 0 deletions
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)