Skip to content

BUG: PeriodIndex._shallow_copy doesn't roundtrip asi8 values correctly #24391

Closed
@jschendel

Description

@jschendel

On master:

In [1]: import pandas as pd; pd.__version__
Out[1]: '0.24.0.dev0+1340.g8c58817bd'

In [2]: pi = pd.period_range('2018-01-01', periods=3, freq='2D')

In [3]: pi
Out[3]: PeriodIndex(['2018-01-01', '2018-01-03', '2018-01-05'], dtype='period[2D]', freq='2D')

In [4]: pi._shallow_copy(pi.asi8, freq=pi.freq)
Out[4]: PeriodIndex(['2018-01-02', '2018-01-04', '2018-01-06'], dtype='period[2D]', freq='2D')

It appears that values are shifted forward by freq.n - 1 base frequencies, e.g. if freq='5D' then the above will result in a shift of '2018-01-01' --> '2018-01-05'.

Note that this is working on 0.23.4:

In [1]: import pandas as pd; pd.__version__
Out[1]: '0.23.4'

In [2]: pi = pd.period_range('2018-01-01', periods=3, freq='2D')

In [3]: pi
Out[3]: PeriodIndex(['2018-01-01', '2018-01-03', '2018-01-05'], dtype='period[2D]', freq='2D')

In [4]: pi._shallow_copy(pi.asi8, freq=pi.freq)
Out[4]: PeriodIndex(['2018-01-01', '2018-01-03', '2018-01-05'], dtype='period[2D]', freq='2D')

cc @jbrockmendel : Am I correct in expecting that Out[3] and Out[4] should be the same?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BlockerBlocking issue or pull request for an upcoming releasePeriodPeriod data typeRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions