We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c980035 commit c4b0b97Copy full SHA for c4b0b97
pandas/core/arrays/base.py
@@ -418,14 +418,17 @@ def shift(self, periods=1):
418
-------
419
shifted : ExtensionArray
420
"""
421
- indexer = np.roll(np.arange(len(self)), periods)
422
-
+ if periods == 0:
+ return self.copy()
423
+ empty = self._from_sequence([self.dtype.na_value] * abs(periods),
424
+ dtype=self.dtype)
425
if periods > 0:
- indexer[:periods] = -1
426
+ a = empty
427
+ b = self[:-periods]
428
else:
- indexer[periods:] = -1
- return self.take(indexer, allow_fill=True)
429
+ a = self[abs(periods):]
430
+ b = empty
431
+ return self._concat_same_type([a, b])
432
433
def unique(self):
434
"""Compute the ExtensionArray of unique values.
0 commit comments