5
5
from typing import (
6
6
TYPE_CHECKING ,
7
7
Any ,
8
- Union ,
8
+ Callable ,
9
9
cast ,
10
10
)
11
11
import warnings
@@ -138,7 +138,7 @@ def newfunc(self, *args, **kwargs) -> list[Block]:
138
138
return cast (F , newfunc )
139
139
140
140
141
- class Block (libinternals . Block , PandasObject ):
141
+ class Block (PandasObject ):
142
142
"""
143
143
Canonical n-dimensional unit of homogeneous dtype contained in a pandas
144
144
data structure
@@ -147,6 +147,8 @@ class Block(libinternals.Block, PandasObject):
147
147
"""
148
148
149
149
values : np .ndarray | ExtensionArray
150
+ ndim : int
151
+ __init__ : Callable
150
152
151
153
__slots__ = ()
152
154
is_numeric = False
@@ -313,7 +315,6 @@ def getitem_block(self, slicer) -> Block:
313
315
314
316
return type (self )(new_values , new_mgr_locs , self .ndim )
315
317
316
- @final
317
318
def getitem_block_index (self , slicer : slice ) -> Block :
318
319
"""
319
320
Perform __getitem__-like specialized to slicing along index.
@@ -1371,7 +1372,7 @@ def interpolate(
1371
1372
return self .make_block_same_class (new_values )
1372
1373
1373
1374
1374
- class ExtensionBlock (EABackedBlock ):
1375
+ class ExtensionBlock (libinternals . Block , EABackedBlock ):
1375
1376
"""
1376
1377
Block for holding extension types.
1377
1378
@@ -1660,7 +1661,13 @@ def _unstack(self, unstacker, fill_value, new_placement):
1660
1661
return blocks , mask
1661
1662
1662
1663
1663
- class NumericBlock (Block ):
1664
+ class NumpyBlock (libinternals .NumpyBlock , Block ):
1665
+ values : np .ndarray
1666
+
1667
+ getitem_block_index = libinternals .NumpyBlock .getitem_block_index
1668
+
1669
+
1670
+ class NumericBlock (NumpyBlock ):
1664
1671
__slots__ = ()
1665
1672
is_numeric = True
1666
1673
@@ -1771,16 +1778,15 @@ def fillna(
1771
1778
return [self .make_block_same_class (values = new_values )]
1772
1779
1773
1780
1774
- class DatetimeLikeBlock (NDArrayBackedExtensionBlock ):
1775
- """Mixin class for DatetimeLikeBlock, DatetimeTZBlock ."""
1781
+ class DatetimeLikeBlock (libinternals . Block , NDArrayBackedExtensionBlock ):
1782
+ """Block for datetime64[ns], timedelta64[ns] ."""
1776
1783
1777
1784
__slots__ = ()
1778
1785
is_numeric = False
1779
-
1780
1786
values : DatetimeArray | TimedeltaArray
1781
1787
1782
1788
1783
- class DatetimeTZBlock (ExtensionBlock , DatetimeLikeBlock ):
1789
+ class DatetimeTZBlock (ExtensionBlock , NDArrayBackedExtensionBlock ):
1784
1790
""" implement a datetime64 block with a tz attribute """
1785
1791
1786
1792
values : DatetimeArray
@@ -1794,18 +1800,15 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeLikeBlock):
1794
1800
putmask = NDArrayBackedExtensionBlock .putmask
1795
1801
fillna = NDArrayBackedExtensionBlock .fillna
1796
1802
1797
- # error: Incompatible types in assignment (expression has type
1798
- # "Callable[[NDArrayBackedExtensionBlock], bool]", base class "ExtensionBlock"
1799
- # defined the type as "bool") [assignment]
1800
- is_view = NDArrayBackedExtensionBlock .is_view # type: ignore[assignment]
1803
+ get_values = NDArrayBackedExtensionBlock .get_values
1804
+
1805
+ is_view = NDArrayBackedExtensionBlock .is_view
1801
1806
1802
1807
1803
- class ObjectBlock (Block ):
1808
+ class ObjectBlock (NumpyBlock ):
1804
1809
__slots__ = ()
1805
1810
is_object = True
1806
1811
1807
- values : np .ndarray
1808
-
1809
1812
@maybe_split
1810
1813
def reduce (self , func , ignore_failures : bool = False ) -> list [Block ]:
1811
1814
"""
@@ -2030,7 +2033,7 @@ def ensure_block_shape(values: ArrayLike, ndim: int = 1) -> ArrayLike:
2030
2033
# TODO(EA2D): https://github.com/pandas-dev/pandas/issues/23023
2031
2034
# block.shape is incorrect for "2D" ExtensionArrays
2032
2035
# We can't, and don't need to, reshape.
2033
- values = cast (Union [ np .ndarray , DatetimeArray , TimedeltaArray ] , values )
2036
+ values = cast (" np.ndarray | DatetimeArray | TimedeltaArray" , values )
2034
2037
values = values .reshape (1 , - 1 )
2035
2038
2036
2039
return values
0 commit comments