Skip to content

Improve error message for StringDtype with invalid storage #55052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")