Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2339,7 +2339,7 @@ def construct_from_string(cls, string: str) -> ArrowDtype:
)
if not string.endswith("[pyarrow]"):
raise TypeError(f"'{string}' must end with '[pyarrow]'")
if string == "string[pyarrow]":
if string in ("string[pyarrow]", "str[pyarrow]"):
# Ensure Registry.find skips ArrowDtype to use StringDtype instead
raise TypeError("string[pyarrow] should be constructed by StringDtype")
if pa_version_under10p1:
Expand Down
20 changes: 20 additions & 0 deletions pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,26 @@ def test_pandas_dtype_string_dtypes(string_storage):
assert result == pd.StringDtype(string_storage, na_value=pd.NA)


def test_pandas_dtype_string_dtype_alias_with_storage():
with pytest.raises(TypeError, match="not understood"):
pandas_dtype("str[python]")

with pytest.raises(TypeError, match="not understood"):
pandas_dtype("str[pyarrow]")

result = pandas_dtype("string[python]")
assert result == pd.StringDtype("python", na_value=pd.NA)

if HAS_PYARROW:
result = pandas_dtype("string[pyarrow]")
assert result == pd.StringDtype("pyarrow", na_value=pd.NA)
else:
with pytest.raises(
ImportError, match="required for PyArrow backed StringArray"
):
pandas_dtype("string[pyarrow]")


@td.skip_if_installed("pyarrow")
def test_construct_from_string_without_pyarrow_installed():
# GH 57928
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/strings/test_get_dummies.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ def test_get_dummies_with_str_dtype(any_string_dtype):
@td.skip_if_no("pyarrow")
def test_get_dummies_with_pa_str_dtype(any_string_dtype):
s = Series(["a|b", "a|c", np.nan], dtype=any_string_dtype)
result = s.str.get_dummies("|", dtype="str[pyarrow]")
result = s.str.get_dummies("|", dtype="string[pyarrow]")
expected = DataFrame(
[
["true", "true", "false"],
["true", "false", "true"],
["false", "false", "false"],
],
columns=list("abc"),
dtype="str[pyarrow]",
dtype="string[pyarrow]",
)
tm.assert_frame_equal(result, expected)
Loading