Skip to content

Support ExtensionArrarys for shift #22386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TomAugspurger opened this issue Aug 16, 2018 · 0 comments
Closed

Support ExtensionArrarys for shift #22386

TomAugspurger opened this issue Aug 16, 2018 · 0 comments
Labels
ExtensionArray Extending pandas with custom dtypes or arrays.
Milestone

Comments

@TomAugspurger
Copy link
Contributor

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)
<ipython-input-3-8c2f15affd64> in <module>()
----> 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'
@TomAugspurger TomAugspurger added the ExtensionArray Extending pandas with custom dtypes or arrays. label Aug 16, 2018
@TomAugspurger TomAugspurger added this to the 0.24.0 milestone Aug 16, 2018
TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Aug 16, 2018
Uses take internally.

Closes pandas-dev#22386
TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Aug 18, 2018
commit b29dfc6
Author: Tom Augspurger <[email protected]>
Date:   Thu Aug 16 10:45:38 2018 -0500

    Support NDFrame.shift with EAs

    Uses take internally.

    Closes pandas-dev#22386

commit b5d81cf
Author: William Ayd <[email protected]>
Date:   Thu Aug 16 03:54:18 2018 -0700

    Bump pytest (pandas-dev#22320)

commit f07a790
Author: jbrockmendel <[email protected]>
Date:   Thu Aug 16 03:46:58 2018 -0700

    Make more of numpy_helper unnecessary (pandas-dev#22344)

commit 7b80d4d
Author: Graham Inggs <[email protected]>
Date:   Thu Aug 16 12:43:02 2018 +0200

    Drop redundant TestLocale (pandas-dev#22349)

commit 6bcfc46
Author: Matthew Roeschke <[email protected]>
Date:   Thu Aug 16 03:32:31 2018 -0700

    Fix failing dateutil test (pandas-dev#22354)

commit 86e8f23
Author: jbrockmendel <[email protected]>
Date:   Thu Aug 16 03:08:09 2018 -0700

    remove last cython: nprofile comments (pandas-dev#22371)

commit 70e6f7c
Author: Joris Van den Bossche <[email protected]>
Date:   Wed Aug 15 18:09:50 2018 +0200

    DOC: edit docstring example to prevent segfault (pandas-dev#21824) (pandas-dev#22368)
TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Aug 18, 2018
commit c4b0b97
Author: Tom Augspurger <[email protected]>
Date:   Thu Aug 16 14:36:39 2018 -0500

    Slice based

commit c980035
Author: Tom Augspurger <[email protected]>
Date:   Thu Aug 16 14:20:21 2018 -0500

    Updated

commit b29dfc6
Author: Tom Augspurger <[email protected]>
Date:   Thu Aug 16 10:45:38 2018 -0500

    Support NDFrame.shift with EAs

    Uses take internally.

    Closes pandas-dev#22386

commit b5d81cf
Author: William Ayd <[email protected]>
Date:   Thu Aug 16 03:54:18 2018 -0700

    Bump pytest (pandas-dev#22320)

commit f07a790
Author: jbrockmendel <[email protected]>
Date:   Thu Aug 16 03:46:58 2018 -0700

    Make more of numpy_helper unnecessary (pandas-dev#22344)

commit 7b80d4d
Author: Graham Inggs <[email protected]>
Date:   Thu Aug 16 12:43:02 2018 +0200

    Drop redundant TestLocale (pandas-dev#22349)

commit 6bcfc46
Author: Matthew Roeschke <[email protected]>
Date:   Thu Aug 16 03:32:31 2018 -0700

    Fix failing dateutil test (pandas-dev#22354)

commit 86e8f23
Author: jbrockmendel <[email protected]>
Date:   Thu Aug 16 03:08:09 2018 -0700

    remove last cython: nprofile comments (pandas-dev#22371)

commit 70e6f7c
Author: Joris Van den Bossche <[email protected]>
Date:   Wed Aug 15 18:09:50 2018 +0200

    DOC: edit docstring example to prevent segfault (pandas-dev#21824) (pandas-dev#22368)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

No branches or pull requests

1 participant