@@ -239,7 +239,7 @@ def array_values(self) -> ExtensionArray:
239
239
"""
240
240
return PandasArray (self .values )
241
241
242
- def get_values (self , dtype : Optional [Dtype ] = None ):
242
+ def get_values (self , dtype : Optional [DtypeObj ] = None ) -> np . ndarray :
243
243
"""
244
244
return an internal format, currently just the ndarray
245
245
this is often overridden to handle to_dense like operations
@@ -282,7 +282,7 @@ def make_block(self, values, placement=None) -> Block:
282
282
283
283
return make_block (values , placement = placement , ndim = self .ndim )
284
284
285
- def make_block_same_class (self , values , placement = None , ndim = None ):
285
+ def make_block_same_class (self , values , placement = None , ndim = None ) -> Block :
286
286
""" Wrap given values in a block of same type as self. """
287
287
if placement is None :
288
288
placement = self .mgr_locs
@@ -318,7 +318,7 @@ def _slice(self, slicer):
318
318
319
319
return self .values [slicer ]
320
320
321
- def getitem_block (self , slicer , new_mgr_locs = None ):
321
+ def getitem_block (self , slicer , new_mgr_locs = None ) -> Block :
322
322
"""
323
323
Perform __getitem__-like, return result as block.
324
324
@@ -338,11 +338,11 @@ def getitem_block(self, slicer, new_mgr_locs=None):
338
338
return type (self )._simple_new (new_values , new_mgr_locs , self .ndim )
339
339
340
340
@property
341
- def shape (self ):
341
+ def shape (self ) -> Shape :
342
342
return self .values .shape
343
343
344
344
@property
345
- def dtype (self ):
345
+ def dtype (self ) -> DtypeObj :
346
346
return self .values .dtype
347
347
348
348
def iget (self , i ):
@@ -1063,7 +1063,7 @@ def f(mask, val, idx):
1063
1063
new_blocks = self .split_and_operate (mask , f , True )
1064
1064
return new_blocks
1065
1065
1066
- def coerce_to_target_dtype (self , other ):
1066
+ def coerce_to_target_dtype (self , other ) -> Block :
1067
1067
"""
1068
1068
coerce the current block to a dtype compat for other
1069
1069
we will return a block, possibly object, and not raise
@@ -1091,13 +1091,13 @@ def interpolate(
1091
1091
coerce : bool = False ,
1092
1092
downcast : Optional [str ] = None ,
1093
1093
** kwargs ,
1094
- ):
1094
+ ) -> List [ Block ] :
1095
1095
1096
1096
inplace = validate_bool_kwarg (inplace , "inplace" )
1097
1097
1098
1098
if not self ._can_hold_na :
1099
1099
# If there are no NAs, then interpolate is a no-op
1100
- return self if inplace else self .copy ()
1100
+ return [ self ] if inplace else [ self .copy ()]
1101
1101
1102
1102
# a fill na type method
1103
1103
try :
@@ -1219,7 +1219,9 @@ def func(yvalues: np.ndarray) -> np.ndarray:
1219
1219
blocks = [self .make_block_same_class (interp_values )]
1220
1220
return self ._maybe_downcast (blocks , downcast )
1221
1221
1222
- def take_nd (self , indexer , axis : int , new_mgr_locs = None , fill_value = lib .no_default ):
1222
+ def take_nd (
1223
+ self , indexer , axis : int , new_mgr_locs = None , fill_value = lib .no_default
1224
+ ) -> Block :
1223
1225
"""
1224
1226
Take values according to indexer and return them as a block.bb
1225
1227
@@ -1256,7 +1258,7 @@ def diff(self, n: int, axis: int = 1) -> List[Block]:
1256
1258
new_values = algos .diff (self .values , n , axis = axis , stacklevel = 7 )
1257
1259
return [self .make_block (values = new_values )]
1258
1260
1259
- def shift (self , periods : int , axis : int = 0 , fill_value = None ):
1261
+ def shift (self , periods : int , axis : int = 0 , fill_value : Any = None ) -> List [ Block ] :
1260
1262
""" shift the block by periods, possibly upcast """
1261
1263
# convert integer to float if necessary. need to do a lot more than
1262
1264
# that, handle boolean etc also
@@ -1369,7 +1371,7 @@ def _unstack(self, unstacker, fill_value, new_placement):
1369
1371
blocks = [make_block (new_values , placement = new_placement )]
1370
1372
return blocks , mask
1371
1373
1372
- def quantile (self , qs , interpolation = "linear" , axis : int = 0 ):
1374
+ def quantile (self , qs , interpolation = "linear" , axis : int = 0 ) -> Block :
1373
1375
"""
1374
1376
compute the quantiles of the
1375
1377
@@ -1521,7 +1523,7 @@ def __init__(self, values, placement, ndim: int):
1521
1523
raise AssertionError ("block.size != values.size" )
1522
1524
1523
1525
@property
1524
- def shape (self ):
1526
+ def shape (self ) -> Shape :
1525
1527
# TODO(EA2D): override unnecessary with 2D EAs
1526
1528
if self .ndim == 1 :
1527
1529
return (len (self .values ),)
@@ -1647,7 +1649,7 @@ def setitem(self, indexer, value):
1647
1649
self .values [indexer ] = value
1648
1650
return self
1649
1651
1650
- def get_values (self , dtype : Optional [Dtype ] = None ):
1652
+ def get_values (self , dtype : Optional [DtypeObj ] = None ) -> np . ndarray :
1651
1653
# ExtensionArrays must be iterable, so this works.
1652
1654
# TODO(EA2D): reshape not needed with 2D EAs
1653
1655
return np .asarray (self .values ).reshape (self .shape )
@@ -1669,7 +1671,7 @@ def to_native_types(self, na_rep="nan", quoting=None, **kwargs):
1669
1671
1670
1672
def take_nd (
1671
1673
self , indexer , axis : int = 0 , new_mgr_locs = None , fill_value = lib .no_default
1672
- ):
1674
+ ) -> Block :
1673
1675
"""
1674
1676
Take values according to indexer and return them as a block.
1675
1677
"""
@@ -1733,7 +1735,9 @@ def _slice(self, slicer):
1733
1735
1734
1736
return self .values [slicer ]
1735
1737
1736
- def fillna (self , value , limit = None , inplace = False , downcast = None ):
1738
+ def fillna (
1739
+ self , value , limit = None , inplace : bool = False , downcast = None
1740
+ ) -> List [Block ]:
1737
1741
values = self .values if inplace else self .values .copy ()
1738
1742
values = values .fillna (value = value , limit = limit )
1739
1743
return [
@@ -1765,9 +1769,7 @@ def diff(self, n: int, axis: int = 1) -> List[Block]:
1765
1769
axis = 0
1766
1770
return super ().diff (n , axis )
1767
1771
1768
- def shift (
1769
- self , periods : int , axis : int = 0 , fill_value : Any = None
1770
- ) -> List [ExtensionBlock ]:
1772
+ def shift (self , periods : int , axis : int = 0 , fill_value : Any = None ) -> List [Block ]:
1771
1773
"""
1772
1774
Shift the block by `periods`.
1773
1775
@@ -1947,7 +1949,7 @@ def _holder(self):
1947
1949
def fill_value (self ):
1948
1950
return np .datetime64 ("NaT" , "ns" )
1949
1951
1950
- def get_values (self , dtype : Optional [Dtype ] = None ):
1952
+ def get_values (self , dtype : Optional [DtypeObj ] = None ) -> np . ndarray :
1951
1953
"""
1952
1954
return object dtype as boxed values, such as Timestamps/Timedelta
1953
1955
"""
@@ -1996,11 +1998,11 @@ def diff(self, n: int, axis: int = 0) -> List[Block]:
1996
1998
TimeDeltaBlock (new_values , placement = self .mgr_locs .indexer , ndim = self .ndim )
1997
1999
]
1998
2000
1999
- def shift (self , periods , axis = 0 , fill_value = None ):
2001
+ def shift (self , periods : int , axis : int = 0 , fill_value : Any = None ) -> List [ Block ] :
2000
2002
# TODO(EA2D) this is unnecessary if these blocks are backed by 2D EAs
2001
2003
values = self .array_values ()
2002
2004
new_values = values .shift (periods , fill_value = fill_value , axis = axis )
2003
- return self .make_block_same_class (new_values )
2005
+ return [ self .make_block_same_class (new_values )]
2004
2006
2005
2007
def to_native_types (self , na_rep = "NaT" , ** kwargs ):
2006
2008
""" convert to our native types format """
@@ -2118,7 +2120,7 @@ def is_view(self) -> bool:
2118
2120
# check the ndarray values of the DatetimeIndex values
2119
2121
return self .values ._data .base is not None
2120
2122
2121
- def get_values (self , dtype : Optional [Dtype ] = None ):
2123
+ def get_values (self , dtype : Optional [DtypeObj ] = None ) -> np . ndarray :
2122
2124
"""
2123
2125
Returns an ndarray of values.
2124
2126
@@ -2157,7 +2159,9 @@ def external_values(self):
2157
2159
return self .values ._data
2158
2160
return np .asarray (self .values .astype ("datetime64[ns]" , copy = False ))
2159
2161
2160
- def fillna (self , value , limit = None , inplace = False , downcast = None ):
2162
+ def fillna (
2163
+ self , value , limit = None , inplace : bool = False , downcast = None
2164
+ ) -> List [Block ]:
2161
2165
# We support filling a DatetimeTZ with a `value` whose timezone
2162
2166
# is different by coercing to object.
2163
2167
if self ._can_hold_element (value ):
@@ -2168,7 +2172,7 @@ def fillna(self, value, limit=None, inplace=False, downcast=None):
2168
2172
value , limit = limit , inplace = inplace , downcast = downcast
2169
2173
)
2170
2174
2171
- def quantile (self , qs , interpolation = "linear" , axis = 0 ) :
2175
+ def quantile (self , qs , interpolation = "linear" , axis : int = 0 ) -> Block :
2172
2176
naive = self .values .view ("M8[ns]" )
2173
2177
2174
2178
# TODO(EA2D): kludge for 2D block with 1D values
@@ -2228,7 +2232,9 @@ def _maybe_coerce_values(self, values):
2228
2232
def _holder (self ):
2229
2233
return TimedeltaArray
2230
2234
2231
- def fillna (self , value , ** kwargs ):
2235
+ def fillna (
2236
+ self , value , limit = None , inplace : bool = False , downcast = None
2237
+ ) -> List [Block ]:
2232
2238
# TODO(EA2D): if we operated on array_values, TDA.fillna would handle
2233
2239
# raising here.
2234
2240
if is_integer (value ):
@@ -2238,7 +2244,7 @@ def fillna(self, value, **kwargs):
2238
2244
"longer supported. To obtain the old behavior, pass "
2239
2245
"`pd.Timedelta(seconds=n)` instead."
2240
2246
)
2241
- return super ().fillna (value , ** kwargs )
2247
+ return super ().fillna (value , limit = limit , inplace = inplace , downcast = downcast )
2242
2248
2243
2249
2244
2250
class ObjectBlock (Block ):
@@ -2450,7 +2456,9 @@ def get_block_type(values, dtype: Optional[Dtype] = None):
2450
2456
return cls
2451
2457
2452
2458
2453
- def make_block (values , placement , klass = None , ndim = None , dtype : Optional [Dtype ] = None ):
2459
+ def make_block (
2460
+ values , placement , klass = None , ndim = None , dtype : Optional [Dtype ] = None
2461
+ ) -> Block :
2454
2462
# Ensure that we don't allow PandasArray / PandasDtype in internals.
2455
2463
# For now, blocks should be backed by ndarrays when possible.
2456
2464
if isinstance (values , ABCPandasArray ):
@@ -2477,7 +2485,7 @@ def make_block(values, placement, klass=None, ndim=None, dtype: Optional[Dtype]
2477
2485
# -----------------------------------------------------------------
2478
2486
2479
2487
2480
- def extend_blocks (result , blocks = None ):
2488
+ def extend_blocks (result , blocks = None ) -> List [ Block ] :
2481
2489
""" return a new extended blocks, given the result """
2482
2490
if blocks is None :
2483
2491
blocks = []
0 commit comments