Skip to content

ExtensionArray.shift incorrect for periods larger than length of array #23911

Closed
@TomAugspurger

Description

@TomAugspurger
In [9]: from pandas.tests.extension.decimal import to_decimal

In [10]: to_decimal([1, 2]).shift(4)
Out[10]:
DecimalArray(array([Decimal('NaN'), Decimal('NaN'), Decimal('NaN'), Decimal('NaN')],
      dtype=object))

The expected output is

>>> to_decimal(['NaN', 'NaN'])
DecimalArray(array([Decimal('NaN'), Decimal('NaN')], dtype=object))

similar to categorical

In [12]: pd.Categorical([1, 2]).shift(4)
Out[12]:
[NaN, NaN]
Categories (2, int64): [1, 2]

This will need a new base test in tests/extension/base/methods.py and a fix in

def shift(self, periods=1):

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions