Skip to content

BUG: parsing pyarrow dtypes corner case #51548

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 4 commits into from
Feb 23, 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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ Metadata

Other
^^^^^

- Bug in incorrectly accepting dtype strings containing "[pyarrow]" more than once (:issue:`51548`)
- Bug in :meth:`Series.searchsorted` inconsistent behavior when accepting :class:`DataFrame` as parameter ``value`` (:issue:`49620`)
- Bug in :func:`array` failing to raise on :class:`DataFrame` inputs (:issue:`51167`)

Expand Down
3 changes: 2 additions & 1 deletion pandas/core/arrays/arrow/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def construct_from_string(cls, string: str) -> ArrowDtype:
if string == "string[pyarrow]":
# Ensure Registry.find skips ArrowDtype to use StringDtype instead
raise TypeError("string[pyarrow] should be constructed by StringDtype")
base_type = string.split("[pyarrow]")[0]

base_type = string[:-9] # get rid of "[pyarrow]"
try:
pa_dtype = pa.type_for_alias(base_type)
except ValueError as err:
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,17 @@ def test_arrowdtype_construct_from_string_type_with_unsupported_parameters():
ArrowDtype.construct_from_string("decimal(7, 2)[pyarrow]")


def test_arrowdtype_construct_from_string_type_only_one_pyarrow():
# GH#51225
invalid = "int64[pyarrow]foobar[pyarrow]"
msg = (
r"Passing pyarrow type specific parameters \(\[pyarrow\]\) in the "
r"string is not supported\."
)
with pytest.raises(NotImplementedError, match=msg):
pd.Series(range(3), dtype=invalid)


@pytest.mark.parametrize(
"interpolation", ["linear", "lower", "higher", "nearest", "midpoint"]
)
Expand Down