Skip to content

Commit

Permalink
Backport PR pandas-dev#55052: Improve error message for StringDtype w…
Browse files Browse the repository at this point in the history
…ith invalid storage
  • Loading branch information
phofl authored and meeseeksmachine committed Sep 7, 2023
1 parent 6db7b00 commit e31cd04
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 @@ -119,7 +119,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 e31cd04

Please sign in to comment.