Skip to content

shift does not always preserve freqstr if series contains only one or two elements #21275

@kdebrab

Description

@kdebrab

Problem description

The freqstr information is lost if series contains only one or two elements AND the freqstr by which is shifted is not the same as the freqstr of the series. In all other cases it works fine.

import pandas as pd
s1 = pd.Series([1], index=pd.date_range('2016-1-1', periods=1, freq='H'))
s2 = pd.Series([1, 2], index=pd.date_range('2016-1-1', periods=2, freq='H'))
s3 = pd.Series([1, 2, 3], index=pd.date_range('2016-1-1', periods=3, freq='H'))

# following DOES NOT preserve freqstr
print(s1.shift(1, '2H'))
print(s2.shift(1, '2H'))
print(s1.shift(1, 'min'))
print(s2.shift(1, 'min'))

# for comparison, following is all OK (preserves freqstr)
print(s1.shift(1, 'H'))
print(s2.shift(1, 'H'))
print(s3.shift(1, 'H'))
print(s3.shift(1, '2H'))
print(s3.shift(1, 'min'))
print(s3.shift(1, 'min'))

Expected Output

Preservation of the freqstr in all above cases.

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 2.7.13.final.0 python-bits: 32 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None pandas: 0.23.0 pytest: None pip: 10.0.1 setuptools: 36.4.0 Cython: None numpy: 1.14.3 scipy: 1.1.0 pyarrow: None xarray: 0.10.0 IPython: 5.3.0 sphinx: 1.6.3 patsy: 0.5.0 dateutil: 2.6.1 pytz: 2018.3 blosc: None bottleneck: 1.2.1 tables: None numexpr: None feather: None matplotlib: 2.2.2 openpyxl: 2.5.3 xlrd: 1.0.0 xlwt: 1.3.0 xlsxwriter: 1.0.4 lxml: 4.2.1 bs4: 4.6.0 html5lib: 0.999999999 sqlalchemy: 1.2.3 pymysql: None psycopg2: None jinja2: 2.10 s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: None

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