@@ -146,7 +146,7 @@ def newfunc(self, *args, **kwargs) -> List[Block]:
146
146
return cast (F , newfunc )
147
147
148
148
149
- class Block (PandasObject ):
149
+ class Block (libinternals . Block , PandasObject ):
150
150
"""
151
151
Canonical n-dimensional unit of homogeneous dtype contained in a pandas
152
152
data structure
@@ -156,43 +156,14 @@ class Block(PandasObject):
156
156
157
157
values : Union [np .ndarray , ExtensionArray ]
158
158
159
- __slots__ = [ "_mgr_locs" , "values" , "ndim" ]
159
+ __slots__ = ()
160
160
is_numeric = False
161
161
is_bool = False
162
162
is_object = False
163
163
is_extension = False
164
164
_can_consolidate = True
165
165
_validate_ndim = True
166
166
167
- @classmethod
168
- def _simple_new (
169
- cls , values : ArrayLike , placement : BlockPlacement , ndim : int
170
- ) -> Block :
171
- """
172
- Fastpath constructor, does *no* validation
173
- """
174
- obj = object .__new__ (cls )
175
- obj .ndim = ndim
176
- obj .values = values
177
- obj ._mgr_locs = placement
178
- return obj
179
-
180
- def __init__ (self , values , placement : BlockPlacement , ndim : int ):
181
- """
182
- Parameters
183
- ----------
184
- values : np.ndarray or ExtensionArray
185
- We assume maybe_coerce_values has already been called.
186
- placement : BlockPlacement (or castable)
187
- ndim : int
188
- 1 for SingleBlockManager/Series, 2 for BlockManager/DataFrame
189
- """
190
- assert isinstance (ndim , int )
191
- assert isinstance (placement , BlockPlacement )
192
- self .ndim = ndim
193
- self ._mgr_locs = placement
194
- self .values = values
195
-
196
167
@final
197
168
@property
198
169
def _consolidate_key (self ):
@@ -277,7 +248,6 @@ def mgr_locs(self) -> BlockPlacement:
277
248
278
249
@mgr_locs .setter
279
250
def mgr_locs (self , new_mgr_locs : BlockPlacement ):
280
- assert isinstance (new_mgr_locs , BlockPlacement )
281
251
self ._mgr_locs = new_mgr_locs
282
252
283
253
@final
@@ -322,16 +292,6 @@ def __repr__(self) -> str:
322
292
def __len__ (self ) -> int :
323
293
return len (self .values )
324
294
325
- @final
326
- def __getstate__ (self ):
327
- return self .mgr_locs .indexer , self .values
328
-
329
- @final
330
- def __setstate__ (self , state ):
331
- self .mgr_locs = libinternals .BlockPlacement (state [0 ])
332
- self .values = extract_array (state [1 ], extract_numpy = True )
333
- self .ndim = self .values .ndim
334
-
335
295
def _slice (self , slicer ):
336
296
""" return a slice of my values """
337
297
@@ -352,7 +312,7 @@ def getitem_block(self, slicer) -> Block:
352
312
if new_values .ndim != self .values .ndim :
353
313
raise ValueError ("Only same dim slicing is allowed" )
354
314
355
- return type (self ). _simple_new (new_values , new_mgr_locs , self .ndim )
315
+ return type (self )(new_values , new_mgr_locs , self .ndim )
356
316
357
317
@final
358
318
def getitem_block_index (self , slicer : slice ) -> Block :
@@ -364,7 +324,7 @@ def getitem_block_index(self, slicer: slice) -> Block:
364
324
# error: Invalid index type "Tuple[ellipsis, slice]" for
365
325
# "Union[ndarray, ExtensionArray]"; expected type "Union[int, slice, ndarray]"
366
326
new_values = self .values [..., slicer ] # type: ignore[index]
367
- return type (self ). _simple_new (new_values , self ._mgr_locs , ndim = self .ndim )
327
+ return type (self )(new_values , self ._mgr_locs , ndim = self .ndim )
368
328
369
329
@final
370
330
def getitem_block_columns (self , slicer , new_mgr_locs : BlockPlacement ) -> Block :
@@ -378,7 +338,7 @@ def getitem_block_columns(self, slicer, new_mgr_locs: BlockPlacement) -> Block:
378
338
if new_values .ndim != self .values .ndim :
379
339
raise ValueError ("Only same dim slicing is allowed" )
380
340
381
- return type (self ). _simple_new (new_values , new_mgr_locs , self .ndim )
341
+ return type (self )(new_values , new_mgr_locs , self .ndim )
382
342
383
343
@property
384
344
def shape (self ) -> Shape :
@@ -1911,7 +1871,7 @@ def set_inplace(self, locs, values):
1911
1871
self .values [locs ] = values
1912
1872
1913
1873
1914
- class DatetimeTZBlock (ExtensionBlock , DatetimeBlock ):
1874
+ class DatetimeTZBlock (ExtensionBlock , DatetimeLikeBlockMixin ):
1915
1875
""" implement a datetime64 block with a tz attribute """
1916
1876
1917
1877
values : DatetimeArray
0 commit comments