Support ExtensionArrarys for shift · Issue #22386 · pandas-dev/pandas (original) (raw)

This is needed for sparse. I have a separate PR incoming

In [2]: import pandas as pd

In [3]: pd.Series([1, 2], dtype='Int8').shift()

AttributeError Traceback (most recent call last) in () ----> 1 pd.Series([1, 2], dtype='Int8').shift()

~/sandbox/pandas/pandas/core/series.py in shift(self, periods, freq, axis) 3476 @Appender(generic._shared_docs['shift'] % _shared_doc_kwargs) 3477 def shift(self, periods=1, freq=None, axis=0): -> 3478 return super(Series, self).shift(periods=periods, freq=freq, axis=axis) 3479 3480 def reindex_axis(self, labels, axis=0, **kwargs):

~/sandbox/pandas/pandas/core/generic.py in shift(self, periods, freq, axis) 8088 block_axis = self._get_block_manager_axis(axis) 8089 if freq is None: -> 8090 new_data = self._data.shift(periods=periods, axis=block_axis) 8091 else: 8092 return self.tshift(periods, freq)

~/sandbox/pandas/pandas/core/internals/managers.py in shift(self, **kwargs) 545 546 def shift(self, **kwargs): --> 547 return self.apply('shift', **kwargs) 548 549 def fillna(self, **kwargs):

~/sandbox/pandas/pandas/core/internals/managers.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs) 421 422 kwargs['mgr'] = self --> 423 applied = getattr(b, f)(**kwargs) 424 result_blocks = _extend_blocks(applied, result_blocks) 425

~/sandbox/pandas/pandas/core/internals/blocks.py in shift(self, periods, axis, mgr) 1289 1290 # make sure array sent to np.roll is c_contiguous -> 1291 f_ordered = new_values.flags.f_contiguous 1292 if f_ordered: 1293 new_values = new_values.T

AttributeError: 'IntegerArray' object has no attribute 'flags'