Skip to content

Commit da9f7b5

Browse files
gfyoungPingviinituutti
authored andcommitted
DEPR: Deprecate FrozenNDArray (pandas-dev#23396)
Closes pandas-devgh-9031.
1 parent a91850d commit da9f7b5

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ Deprecations
953953
- :func:`DatetimeIndex.shift` and :func:`PeriodIndex.shift` now accept ``periods`` argument instead of ``n`` for consistency with :func:`Index.shift` and :func:`Series.shift`. Using ``n`` throws a deprecation warning (:issue:`22458`, :issue:`22912`)
954954
- The ``fastpath`` keyword of the different Index constructors is deprecated (:issue:`23110`).
955955
- :meth:`Timestamp.tz_localize`, :meth:`DatetimeIndex.tz_localize`, and :meth:`Series.tz_localize` have deprecated the ``errors`` argument in favor of the ``nonexistent`` argument (:issue:`8917`)
956+
- The class ``FrozenNDArray`` has been deprecated. When unpickling, ``FrozenNDArray`` will be unpickled to ``np.ndarray`` once this class is removed (:issue:`9031`)
956957

957958
.. _whatsnew_0240.prior_deprecations:
958959

pandas/compat/pickle_compat.py

+11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ def load_reduce(self):
6060
('pandas.core.arrays', 'SparseArray'),
6161

6262
# 15477
63+
#
64+
# TODO: When FrozenNDArray is removed, add
65+
# the following lines for compat:
66+
#
67+
# ('pandas.core.base', 'FrozenNDArray'):
68+
# ('numpy', 'ndarray'),
69+
# ('pandas.core.indexes.frozen', 'FrozenNDArray'):
70+
# ('numpy', 'ndarray'),
71+
#
72+
# Afterwards, remove the current entry
73+
# for `pandas.core.base.FrozenNDArray`.
6374
('pandas.core.base', 'FrozenNDArray'):
6475
('pandas.core.indexes.frozen', 'FrozenNDArray'),
6576
('pandas.core.base', 'FrozenList'):

pandas/core/indexes/frozen.py

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
"""
1010

11+
import warnings
1112
import numpy as np
1213
from pandas.core.base import PandasObject
1314
from pandas.util._decorators import deprecate_kwarg
@@ -86,6 +87,10 @@ class FrozenNDArray(PandasObject, np.ndarray):
8687

8788
# no __array_finalize__ for now because no metadata
8889
def __new__(cls, data, dtype=None, copy=False):
90+
warnings.warn("\nFrozenNDArray is deprecated and will be removed in a "
91+
"future version.\nPlease use `numpy.ndarray` instead.\n",
92+
FutureWarning, stacklevel=2)
93+
8994
if copy is None:
9095
copy = not isinstance(data, FrozenNDArray)
9196
res = np.array(data, dtype=dtype, copy=copy).view(cls)

pandas/core/indexes/multi.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
Index, ensure_index,
4141
InvalidIndexError,
4242
_index_shared_docs)
43-
from pandas.core.indexes.frozen import (
44-
FrozenNDArray, FrozenList, _ensure_frozen)
43+
from pandas.core.indexes.frozen import FrozenList, _ensure_frozen
4544
import pandas.core.indexes.base as ibase
4645
_index_doc_kwargs = dict(ibase._index_doc_kwargs)
4746
_index_doc_kwargs.update(
@@ -1655,7 +1654,7 @@ def _assert_take_fillable(self, values, indices, allow_fill=True,
16551654
for new_label in taken:
16561655
label_values = new_label.values()
16571656
label_values[mask] = na_value
1658-
masked.append(FrozenNDArray(label_values))
1657+
masked.append(np.asarray(label_values))
16591658
taken = masked
16601659
else:
16611660
taken = [lab.take(indices) for lab in self.labels]

pandas/tests/indexes/test_frozen.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
import numpy as np
23

34
from pandas.compat import u
@@ -34,13 +35,23 @@ def test_inplace(self):
3435

3536
class TestFrozenNDArray(CheckImmutable, CheckStringMixin):
3637
mutable_methods = ('put', 'itemset', 'fill')
37-
unicode_container = FrozenNDArray([u("\u05d0"), u("\u05d1"), "c"])
3838

39-
def setup_method(self, method):
39+
def setup_method(self, _):
4040
self.lst = [3, 5, 7, -2]
41-
self.container = FrozenNDArray(self.lst)
4241
self.klass = FrozenNDArray
4342

43+
with warnings.catch_warnings(record=True):
44+
warnings.simplefilter("ignore", FutureWarning)
45+
46+
self.container = FrozenNDArray(self.lst)
47+
self.unicode_container = FrozenNDArray(
48+
[u("\u05d0"), u("\u05d1"), "c"])
49+
50+
def test_constructor_warns(self):
51+
# see gh-9031
52+
with tm.assert_produces_warning(FutureWarning):
53+
FrozenNDArray([1, 2, 3])
54+
4455
def test_shallow_copying(self):
4556
original = self.container.copy()
4657
assert isinstance(self.container.view(), FrozenNDArray)

0 commit comments

Comments
 (0)