Skip to content
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

Support ExtensionArrarys for shift #22386

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

Comments

Projects
None yet
1 participant
@TomAugspurger
Copy link
Contributor

commented Aug 16, 2018

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 this to the 0.24.0 milestone Aug 16, 2018

TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Aug 16, 2018

Support NDFrame.shift with EAs
Uses take internally.

Closes pandas-dev#22386

TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Aug 18, 2018

Squashed commit of the following:
commit b29dfc6
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
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 <william.ayd@icloud.com>
Date:   Thu Aug 16 03:54:18 2018 -0700

    Bump pytest (pandas-dev#22320)

commit f07a790
Author: jbrockmendel <jbrockmendel@gmail.com>
Date:   Thu Aug 16 03:46:58 2018 -0700

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

commit 7b80d4d
Author: Graham Inggs <graham.inggs+github@gmail.com>
Date:   Thu Aug 16 12:43:02 2018 +0200

    Drop redundant TestLocale (pandas-dev#22349)

commit 6bcfc46
Author: Matthew Roeschke <emailformattr@gmail.com>
Date:   Thu Aug 16 03:32:31 2018 -0700

    Fix failing dateutil test (pandas-dev#22354)

commit 86e8f23
Author: jbrockmendel <jbrockmendel@gmail.com>
Date:   Thu Aug 16 03:08:09 2018 -0700

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

commit 70e6f7c
Author: Joris Van den Bossche <jorisvandenbossche@gmail.com>
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

Squashed commit of the following:
commit c4b0b97
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Thu Aug 16 14:36:39 2018 -0500

    Slice based

commit c980035
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
Date:   Thu Aug 16 14:20:21 2018 -0500

    Updated

commit b29dfc6
Author: Tom Augspurger <tom.w.augspurger@gmail.com>
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 <william.ayd@icloud.com>
Date:   Thu Aug 16 03:54:18 2018 -0700

    Bump pytest (pandas-dev#22320)

commit f07a790
Author: jbrockmendel <jbrockmendel@gmail.com>
Date:   Thu Aug 16 03:46:58 2018 -0700

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

commit 7b80d4d
Author: Graham Inggs <graham.inggs+github@gmail.com>
Date:   Thu Aug 16 12:43:02 2018 +0200

    Drop redundant TestLocale (pandas-dev#22349)

commit 6bcfc46
Author: Matthew Roeschke <emailformattr@gmail.com>
Date:   Thu Aug 16 03:32:31 2018 -0700

    Fix failing dateutil test (pandas-dev#22354)

commit 86e8f23
Author: jbrockmendel <jbrockmendel@gmail.com>
Date:   Thu Aug 16 03:08:09 2018 -0700

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

commit 70e6f7c
Author: Joris Van den Bossche <jorisvandenbossche@gmail.com>
Date:   Wed Aug 15 18:09:50 2018 +0200

    DOC: edit docstring example to prevent segfault (pandas-dev#21824) (pandas-dev#22368)

@varadgunjal varadgunjal referenced this issue Nov 27, 2018

Merged

Fixing shift() for ExtensionArray #23947

4 of 4 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.