Skip to content

Commit 1908f2e

Browse files
String dtype: deprecate the pyarrow_numpy storage option (pandas-dev#60152)
* String dtype: deprecate the pyarrow_numpy storage option * add pyarrow skip
1 parent e26e3ee commit 1908f2e

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

doc/source/whatsnew/v2.3.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ notable_bug_fix1
5454
Deprecations
5555
~~~~~~~~~~~~
5656
- 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`)
57-
-
57+
- Deprecated the ``"pyarrow_numpy"`` storage option for :class:`StringDtype` (:issue:`60152`)
5858

5959
.. ---------------------------------------------------------------------------
6060
.. _whatsnew_230.performance:

pandas/core/arrays/string_.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Literal,
88
cast,
99
)
10+
import warnings
1011

1112
import numpy as np
1213

@@ -27,6 +28,7 @@
2728
)
2829
from pandas.compat.numpy import function as nv
2930
from pandas.util._decorators import doc
31+
from pandas.util._exceptions import find_stack_level
3032

3133
from pandas.core.dtypes.base import (
3234
ExtensionDtype,
@@ -154,7 +156,16 @@ def __init__(
154156
storage = "python"
155157

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

@@ -254,7 +265,7 @@ def construct_from_string(cls, string) -> Self:
254265
elif string == "string[pyarrow]":
255266
return cls(storage="pyarrow")
256267
elif string == "string[pyarrow_numpy]":
257-
# TODO deprecate
268+
# this is deprecated in the dtype __init__, remove this in pandas 3.0
258269
return cls(storage="pyarrow_numpy")
259270
else:
260271
raise TypeError(f"Cannot construct a '{cls.__name__}' from '{string}'")

pandas/tests/arrays/string_/test_string.py

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ def cls(dtype):
4242
return dtype.construct_array_type()
4343

4444

45+
def test_dtype_constructor():
46+
pytest.importorskip("pyarrow")
47+
48+
with tm.assert_produces_warning(FutureWarning):
49+
dtype = pd.StringDtype("pyarrow_numpy")
50+
assert dtype == pd.StringDtype("pyarrow", na_value=np.nan)
51+
52+
4553
def test_dtype_equality():
4654
pytest.importorskip("pyarrow")
4755

pandas/tests/extension/test_string.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def test_eq_with_str(self, dtype):
105105
# only the NA-variant supports parametrized string alias
106106
assert dtype == f"string[{dtype.storage}]"
107107
elif dtype.storage == "pyarrow":
108-
# TODO(infer_string) deprecate this
109-
assert dtype == "string[pyarrow_numpy]"
108+
with tm.assert_produces_warning(FutureWarning):
109+
assert dtype == "string[pyarrow_numpy]"
110110

111111
def test_is_not_string_type(self, dtype):
112112
# Different from BaseDtypeTests.test_is_not_string_type

0 commit comments

Comments
 (0)