Skip to content

Commit 3713834

Browse files
authored
REF: rename PandasArray->NumpyExtensionArray (#54101)
* REF: rename PandasArray->NumpyExtensionArray * document PandasDtype->NumpyEADtype
1 parent f77a0e6 commit 3713834

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+293
-252
lines changed

ci/code_checks.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
105105
pandas.api.indexers.VariableOffsetWindowIndexer \
106106
pandas.api.extensions.ExtensionDtype \
107107
pandas.api.extensions.ExtensionArray \
108-
pandas.arrays.PandasArray \
108+
pandas.arrays.NumpyExtensionArray \
109109
pandas.api.extensions.ExtensionArray._accumulate \
110110
pandas.api.extensions.ExtensionArray._concat_same_type \
111111
pandas.api.extensions.ExtensionArray._formatter \

doc/source/development/contributing_codebase.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ be located.
475475

476476
8) Is your test for one of the pandas-provided ExtensionArrays (``Categorical``,
477477
``DatetimeArray``, ``TimedeltaArray``, ``PeriodArray``, ``IntervalArray``,
478-
``PandasArray``, ``FloatArray``, ``BoolArray``, ``StringArray``)?
478+
``NumpyExtensionArray``, ``FloatArray``, ``BoolArray``, ``StringArray``)?
479479
This test likely belongs in one of:
480480

481481
- tests.arrays

doc/source/reference/extensions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ objects.
2424
:template: autosummary/class_without_autosummary.rst
2525

2626
api.extensions.ExtensionArray
27-
arrays.PandasArray
27+
arrays.NumpyExtensionArray
2828

2929
.. We need this autosummary so that methods and attributes are generated.
3030
.. Separate block, since they aren't classes.

doc/source/whatsnew/v2.1.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for mor
286286

287287
Other API changes
288288
^^^^^^^^^^^^^^^^^
289+
- :class:`arrays.PandasArray` has been renamed ``NumpyExtensionArray`` and the attached dtype name changed from ``PandasDtype`` to ``NumpyEADtype``; importing ``PandasArray`` still works until the next major version (:issue:`53694`)
289290
-
290291

291292
.. ---------------------------------------------------------------------------

pandas/_testing/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
from pandas.core.arrays import (
103103
BaseMaskedArray,
104104
ExtensionArray,
105-
PandasArray,
105+
NumpyExtensionArray,
106106
)
107107
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray
108108
from pandas.core.construction import extract_array
@@ -307,7 +307,7 @@ def box_expected(expected, box_cls, transpose: bool = True):
307307
if box_cls is pd.array:
308308
if isinstance(expected, RangeIndex):
309309
# pd.array would return an IntegerArray
310-
expected = PandasArray(np.asarray(expected._values))
310+
expected = NumpyExtensionArray(np.asarray(expected._values))
311311
else:
312312
expected = pd.array(expected, copy=False)
313313
elif box_cls is Index:

pandas/_testing/asserters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
CategoricalDtype,
2626
DatetimeTZDtype,
2727
ExtensionDtype,
28-
PandasDtype,
28+
NumpyEADtype,
2929
)
3030
from pandas.core.dtypes.missing import array_equivalent
3131

@@ -577,12 +577,12 @@ def raise_assert_detail(
577577

578578
if isinstance(left, np.ndarray):
579579
left = pprint_thing(left)
580-
elif isinstance(left, (CategoricalDtype, PandasDtype, StringDtype)):
580+
elif isinstance(left, (CategoricalDtype, NumpyEADtype, StringDtype)):
581581
left = repr(left)
582582

583583
if isinstance(right, np.ndarray):
584584
right = pprint_thing(right)
585-
elif isinstance(right, (CategoricalDtype, PandasDtype, StringDtype)):
585+
elif isinstance(right, (CategoricalDtype, NumpyEADtype, StringDtype)):
586586
right = repr(right)
587587

588588
msg += f"""

pandas/arrays/__init__.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
FloatingArray,
1313
IntegerArray,
1414
IntervalArray,
15-
PandasArray,
15+
NumpyExtensionArray,
1616
PeriodArray,
1717
SparseArray,
1818
StringArray,
@@ -28,9 +28,26 @@
2828
"FloatingArray",
2929
"IntegerArray",
3030
"IntervalArray",
31-
"PandasArray",
31+
"NumpyExtensionArray",
3232
"PeriodArray",
3333
"SparseArray",
3434
"StringArray",
3535
"TimedeltaArray",
3636
]
37+
38+
39+
def __getattr__(name: str):
40+
if name == "PandasArray":
41+
# GH#53694
42+
import warnings
43+
44+
from pandas.util._exceptions import find_stack_level
45+
46+
warnings.warn(
47+
"PandasArray has been renamed NumpyExtensionArray. Use that "
48+
"instead. This alias will be removed in a future version.",
49+
FutureWarning,
50+
stacklevel=find_stack_level(),
51+
)
52+
return NumpyExtensionArray
53+
raise AttributeError(f"module 'pandas.arrays' has no attribute '{name}'")

pandas/core/algorithms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
BaseMaskedDtype,
5959
CategoricalDtype,
6060
ExtensionDtype,
61-
PandasDtype,
61+
NumpyEADtype,
6262
)
6363
from pandas.core.dtypes.generic import (
6464
ABCDatetimeArray,
@@ -1439,8 +1439,8 @@ def diff(arr, n: int, axis: AxisInt = 0):
14391439
else:
14401440
op = operator.sub
14411441

1442-
if isinstance(dtype, PandasDtype):
1443-
# PandasArray cannot necessarily hold shifted versions of itself.
1442+
if isinstance(dtype, NumpyEADtype):
1443+
# NumpyExtensionArray cannot necessarily hold shifted versions of itself.
14441444
arr = arr.to_numpy()
14451445
dtype = arr.dtype
14461446

pandas/core/arrays/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pandas.core.arrays.integer import IntegerArray
1212
from pandas.core.arrays.interval import IntervalArray
1313
from pandas.core.arrays.masked import BaseMaskedArray
14-
from pandas.core.arrays.numpy_ import PandasArray
14+
from pandas.core.arrays.numpy_ import NumpyExtensionArray
1515
from pandas.core.arrays.period import (
1616
PeriodArray,
1717
period_array,
@@ -34,7 +34,7 @@
3434
"FloatingArray",
3535
"IntegerArray",
3636
"IntervalArray",
37-
"PandasArray",
37+
"NumpyExtensionArray",
3838
"PeriodArray",
3939
"period_array",
4040
"SparseArray",

pandas/core/arrays/_mixins.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ def fillna(self, value=None, method=None, limit: int | None = None) -> Self:
317317
func(npvalues, limit=limit, mask=mask.T)
318318
npvalues = npvalues.T
319319

320-
# TODO: PandasArray didn't used to copy, need tests for this
320+
# TODO: NumpyExtensionArray didn't used to copy, need tests
321+
# for this
321322
new_values = self._from_backing_data(npvalues)
322323
else:
323324
# fill with value

0 commit comments

Comments
 (0)