Skip to content

Commit

Permalink
Improve error message for StringDtype with invalid storage
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl committed Sep 7, 2023
1 parent faeedad commit f2ad388
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def __init__(self, storage=None) -> None:
storage = get_option("mode.string_storage")
if storage not in {"python", "pyarrow", "pyarrow_numpy"}:
raise ValueError(
f"Storage must be 'python' or 'pyarrow'. Got {storage} instead."
f"Storage must be 'python', 'pyarrow' or 'pyarrow_numpy'. "
f"Got {storage} instead."
)
if storage in ("pyarrow", "pyarrow_numpy") and pa_version_under7p0:
raise ImportError(
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/arrays/string_/test_string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,11 @@ def test_pickle_roundtrip():

result_sliced = pickle.loads(sliced_pickled)
tm.assert_series_equal(result_sliced, expected_sliced)


@skip_if_no_pyarrow
def test_string_dtype_error_message():
# GH#55051
msg = "Storage must be 'python', 'pyarrow' or 'pyarrow_numpy'."
with pytest.raises(ValueError, match=msg):
StringDtype("bla")

0 comments on commit f2ad388

Please sign in to comment.