Skip to content

Commit

Permalink
Backport PR #55052 on branch 2.1.x (Improve error message for StringD…
Browse files Browse the repository at this point in the history
…type with invalid storage) (#55053)

Backport PR #55052: Improve error message for StringDtype with invalid storage

Co-authored-by: Patrick Hoefler <61934744+phofl@users.noreply.github.com>
  • Loading branch information
meeseeksmachine and phofl committed Sep 7, 2023
1 parent 6db7b00 commit 77d29db
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 77d29db

Please sign in to comment.