Skip to content

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

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
kdebrab opened this issue May 31, 2018 · 2 comments · Fixed by #34572
Closed

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

kdebrab opened this issue May 31, 2018 · 2 comments · Fixed by #34572
Labels
Datetime Datetime data dtype Frequency DateOffsets good first issue Needs Tests Unit test(s) needed to prevent regressions Period Period data type
Milestone

Comments

@kdebrab
Copy link
Contributor

kdebrab commented May 31, 2018

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
@mroeschke mroeschke added Datetime Datetime data dtype Frequency DateOffsets labels Jan 13, 2019
@mroeschke
Copy link
Member

Frequency looks preserved now. Could use a test

In [71]: 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'))
2016-01-01 02:00:00    1
Freq: H, dtype: int64
2016-01-01 02:00:00    1
2016-01-01 03:00:00    2
Freq: H, dtype: int64
2016-01-01 00:01:00    1
Freq: H, dtype: int64
2016-01-01 00:01:00    1
2016-01-01 01:01:00    2
Freq: H, dtype: int64

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Frequency DateOffsets Datetime Datetime data dtype labels Apr 1, 2020
@ghost
Copy link

ghost commented Jun 4, 2020

take

@github-actions github-actions bot assigned ghost Jun 4, 2020
@jreback jreback added this to the 1.1 milestone Jun 4, 2020
@jreback jreback added Frequency DateOffsets Period Period data type Datetime Datetime data dtype labels Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Frequency DateOffsets good first issue Needs Tests Unit test(s) needed to prevent regressions Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants