Skip to content

Commit c4b0b97

Browse files
committed
Slice based
1 parent c980035 commit c4b0b97

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pandas/core/arrays/base.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,17 @@ def shift(self, periods=1):
418418
-------
419419
shifted : ExtensionArray
420420
"""
421-
indexer = np.roll(np.arange(len(self)), periods)
422-
421+
if periods == 0:
422+
return self.copy()
423+
empty = self._from_sequence([self.dtype.na_value] * abs(periods),
424+
dtype=self.dtype)
423425
if periods > 0:
424-
indexer[:periods] = -1
426+
a = empty
427+
b = self[:-periods]
425428
else:
426-
indexer[periods:] = -1
427-
428-
return self.take(indexer, allow_fill=True)
429+
a = self[abs(periods):]
430+
b = empty
431+
return self._concat_same_type([a, b])
429432

430433
def unique(self):
431434
"""Compute the ExtensionArray of unique values.

0 commit comments

Comments
 (0)