Skip to content

Commit

Permalink
Slice based
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Aug 16, 2018
1 parent c980035 commit c4b0b97
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,17 @@ def shift(self, periods=1):
-------
shifted : ExtensionArray
"""
indexer = np.roll(np.arange(len(self)), periods)

if periods == 0:
return self.copy()
empty = self._from_sequence([self.dtype.na_value] * abs(periods),
dtype=self.dtype)
if periods > 0:
indexer[:periods] = -1
a = empty
b = self[:-periods]
else:
indexer[periods:] = -1

return self.take(indexer, allow_fill=True)
a = self[abs(periods):]
b = empty
return self._concat_same_type([a, b])

def unique(self):
"""Compute the ExtensionArray of unique values.
Expand Down

0 comments on commit c4b0b97

Please sign in to comment.