13
13
Union ,
14
14
cast ,
15
15
)
16
+ import warnings
16
17
17
18
import numpy as np
18
19
@@ -192,16 +193,6 @@ def __init__(self, values, placement: BlockPlacement, ndim: int):
192
193
self ._mgr_locs = placement
193
194
self .values = values
194
195
195
- @property
196
- def _holder (self ):
197
- """
198
- The array-like that can hold the underlying values.
199
-
200
- None for 'Block', overridden by subclasses that don't
201
- use an ndarray.
202
- """
203
- return None
204
-
205
196
@final
206
197
@property
207
198
def _consolidate_key (self ):
@@ -228,7 +219,14 @@ def _can_hold_na(self) -> bool:
228
219
@final
229
220
@property
230
221
def is_categorical (self ) -> bool :
231
- return self ._holder is Categorical
222
+ warnings .warn (
223
+ "Block.is_categorical is deprecated and will be removed in a "
224
+ "future version. Use isinstance(block.values, Categorical) "
225
+ "instead. See https://github.com/pandas-dev/pandas/issues/40226" ,
226
+ DeprecationWarning ,
227
+ stacklevel = 2 ,
228
+ )
229
+ return isinstance (self .values , Categorical )
232
230
233
231
@final
234
232
def external_values (self ):
@@ -798,8 +796,10 @@ def _replace_list(
798
796
"""
799
797
See BlockManager._replace_list docstring.
800
798
"""
799
+ values = self .values
800
+
801
801
# TODO: dont special-case Categorical
802
- if self . is_categorical and len (algos .unique (dest_list )) == 1 :
802
+ if isinstance ( values , Categorical ) and len (algos .unique (dest_list )) == 1 :
803
803
# We likely got here by tiling value inside NDFrame.replace,
804
804
# so un-tile here
805
805
return self .replace (src_list , dest_list [0 ], inplace , regex )
@@ -814,17 +814,17 @@ def _replace_list(
814
814
815
815
src_len = len (pairs ) - 1
816
816
817
- if self . is_object :
817
+ if values . dtype == _dtype_obj :
818
818
# Calculate the mask once, prior to the call of comp
819
819
# in order to avoid repeating the same computations
820
- mask = ~ isna (self . values )
820
+ mask = ~ isna (values )
821
821
masks = [
822
- compare_or_regex_search (self . values , s [0 ], regex = regex , mask = mask )
822
+ compare_or_regex_search (values , s [0 ], regex = regex , mask = mask )
823
823
for s in pairs
824
824
]
825
825
else :
826
826
# GH#38086 faster if we know we dont need to check for regex
827
- masks = [missing .mask_missing (self . values , s [0 ]) for s in pairs ]
827
+ masks = [missing .mask_missing (values , s [0 ]) for s in pairs ]
828
828
829
829
# error: Argument 1 to "extract_bool_array" has incompatible type
830
830
# "Union[ExtensionArray, ndarray, bool]"; expected "Union[ExtensionArray,
@@ -1503,11 +1503,6 @@ def putmask(self, mask, new) -> List[Block]:
1503
1503
new_values [mask ] = new
1504
1504
return [self .make_block (values = new_values )]
1505
1505
1506
- @property
1507
- def _holder (self ):
1508
- # For extension blocks, the holder is values-dependent.
1509
- return type (self .values )
1510
-
1511
1506
@property
1512
1507
def is_view (self ) -> bool :
1513
1508
"""Extension arrays are never treated as views."""
@@ -1713,7 +1708,7 @@ def where(self, other, cond, errors="raise") -> List[Block]:
1713
1708
# NotImplementedError for class not implementing `__setitem__`
1714
1709
# TypeError for SparseArray, which implements just to raise
1715
1710
# a TypeError
1716
- result = self ._holder ._from_sequence (
1711
+ result = type ( self .values ) ._from_sequence (
1717
1712
np .where (cond , self .values , other ), dtype = dtype
1718
1713
)
1719
1714
@@ -1903,10 +1898,6 @@ class DatetimeLikeBlockMixin(NDArrayBackedExtensionBlock):
1903
1898
def array_values (self ):
1904
1899
return ensure_wrapped_if_datetimelike (self .values )
1905
1900
1906
- @property
1907
- def _holder (self ):
1908
- return type (self .array_values ())
1909
-
1910
1901
1911
1902
class DatetimeBlock (DatetimeLikeBlockMixin ):
1912
1903
__slots__ = ()
0 commit comments