@@ -1473,12 +1473,11 @@ def diff(self, n: int) -> list[Block]:
1473
1473
new_values = algos .diff (self .values .T , n , axis = 0 ).T
1474
1474
return [self .make_block (values = new_values )]
1475
1475
1476
- def shift (
1477
- self , periods : int , axis : AxisInt = 0 , fill_value : Any = None
1478
- ) -> list [Block ]:
1476
+ def shift (self , periods : int , fill_value : Any = None ) -> list [Block ]:
1479
1477
"""shift the block by periods, possibly upcast"""
1480
1478
# convert integer to float if necessary. need to do a lot more than
1481
1479
# that, handle boolean etc also
1480
+ axis = self .ndim - 1
1482
1481
1483
1482
# Note: periods is never 0 here, as that is handled at the top of
1484
1483
# NDFrame.shift. If that ever changes, we can do a check for periods=0
@@ -1500,12 +1499,12 @@ def shift(
1500
1499
)
1501
1500
except LossySetitemError :
1502
1501
nb = self .coerce_to_target_dtype (fill_value )
1503
- return nb .shift (periods , axis = axis , fill_value = fill_value )
1502
+ return nb .shift (periods , fill_value = fill_value )
1504
1503
1505
1504
else :
1506
1505
values = cast (np .ndarray , self .values )
1507
1506
new_values = shift (values , periods , axis , casted )
1508
- return [self .make_block (new_values )]
1507
+ return [self .make_block_same_class (new_values )]
1509
1508
1510
1509
@final
1511
1510
def quantile (
@@ -1656,6 +1655,18 @@ class EABackedBlock(Block):
1656
1655
1657
1656
values : ExtensionArray
1658
1657
1658
+ def shift (self , periods : int , fill_value : Any = None ) -> list [Block ]:
1659
+ """
1660
+ Shift the block by `periods`.
1661
+
1662
+ Dispatches to underlying ExtensionArray and re-boxes in an
1663
+ ExtensionBlock.
1664
+ """
1665
+ # Transpose since EA.shift is always along axis=0, while we want to shift
1666
+ # along rows.
1667
+ new_values = self .values .T .shift (periods = periods , fill_value = fill_value ).T
1668
+ return [self .make_block_same_class (new_values )]
1669
+
1659
1670
def setitem (self , indexer , value , using_cow : bool = False ):
1660
1671
"""
1661
1672
Attempt self.values[indexer] = value, possibly creating a new array.
@@ -2108,18 +2119,6 @@ def slice_block_rows(self, slicer: slice) -> Self:
2108
2119
new_values = self .values [slicer ]
2109
2120
return type (self )(new_values , self ._mgr_locs , ndim = self .ndim , refs = self .refs )
2110
2121
2111
- def shift (
2112
- self , periods : int , axis : AxisInt = 0 , fill_value : Any = None
2113
- ) -> list [Block ]:
2114
- """
2115
- Shift the block by `periods`.
2116
-
2117
- Dispatches to underlying ExtensionArray and re-boxes in an
2118
- ExtensionBlock.
2119
- """
2120
- new_values = self .values .shift (periods = periods , fill_value = fill_value )
2121
- return [self .make_block_same_class (new_values )]
2122
-
2123
2122
def _unstack (
2124
2123
self ,
2125
2124
unstacker ,
@@ -2226,13 +2225,6 @@ def is_view(self) -> bool:
2226
2225
# check the ndarray values of the DatetimeIndex values
2227
2226
return self .values ._ndarray .base is not None
2228
2227
2229
- def shift (
2230
- self , periods : int , axis : AxisInt = 0 , fill_value : Any = None
2231
- ) -> list [Block ]:
2232
- values = self .values
2233
- new_values = values .shift (periods , fill_value = fill_value , axis = axis )
2234
- return [self .make_block_same_class (new_values )]
2235
-
2236
2228
2237
2229
def _catch_deprecated_value_error (err : Exception ) -> None :
2238
2230
"""
0 commit comments