Skip to content
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

String dtype: deprecate the pyarrow_numpy storage option #60152

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.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ notable_bug_fix1
Deprecations
~~~~~~~~~~~~
- Deprecated allowing non-``bool`` values for ``na`` in :meth:`.str.contains`, :meth:`.str.startswith`, and :meth:`.str.endswith` for dtypes that do not already disallow these (:issue:`59615`)
-
- Deprecated the ``"pyarrow_numpy"`` storage option for :class:`StringDtype` (:issue:`60152`)

.. ---------------------------------------------------------------------------
.. _whatsnew_230.performance:
Expand Down
15 changes: 13 additions & 2 deletions pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Literal,
cast,
)
import warnings

import numpy as np

Expand All @@ -27,6 +28,7 @@
)
from pandas.compat.numpy import function as nv
from pandas.util._decorators import doc
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.base import (
ExtensionDtype,
Expand Down Expand Up @@ -154,7 +156,16 @@ def __init__(
storage = "python"

if storage == "pyarrow_numpy":
# TODO raise a deprecation warning
warnings.warn(
"The 'pyarrow_numpy' storage option name is deprecated and will be "
'removed in pandas 3.0. Use \'pd.StringDtype(storage="pyarrow", '
"na_value-np.nan)' to construct the same dtype.\nOr enable the "
"'pd.options.future.infer_string = True' option globally and use "
'the "str" alias as a shorthand notation to specify a dtype '
'(instead of "string[pyarrow_numpy]").',
FutureWarning,
stacklevel=find_stack_level(),
)
storage = "pyarrow"
na_value = np.nan

Expand Down Expand Up @@ -254,7 +265,7 @@ def construct_from_string(cls, string) -> Self:
elif string == "string[pyarrow]":
return cls(storage="pyarrow")
elif string == "string[pyarrow_numpy]":
# TODO deprecate
# this is deprecated in the dtype __init__, remove this in pandas 3.0
return cls(storage="pyarrow_numpy")
else:
raise TypeError(f"Cannot construct a '{cls.__name__}' from '{string}'")
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/arrays/string_/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def cls(dtype):
return dtype.construct_array_type()


def test_dtype_constructor():
pytest.importorskip("pyarrow")

with tm.assert_produces_warning(FutureWarning):
dtype = pd.StringDtype("pyarrow_numpy")
assert dtype == pd.StringDtype("pyarrow", na_value=np.nan)


def test_dtype_equality():
pytest.importorskip("pyarrow")

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/extension/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def test_eq_with_str(self, dtype):
# only the NA-variant supports parametrized string alias
assert dtype == f"string[{dtype.storage}]"
elif dtype.storage == "pyarrow":
# TODO(infer_string) deprecate this
assert dtype == "string[pyarrow_numpy]"
with tm.assert_produces_warning(FutureWarning):
assert dtype == "string[pyarrow_numpy]"

def test_is_not_string_type(self, dtype):
# Different from BaseDtypeTests.test_is_not_string_type
Expand Down