Skip to content

Adding offset to Timestamp discards freq information when freq="M" or "W" #27182

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
lostella opened this issue Jul 2, 2019 · 3 comments · Fixed by #27192
Closed

Adding offset to Timestamp discards freq information when freq="M" or "W" #27182

lostella opened this issue Jul 2, 2019 · 3 comments · Fixed by #27192
Labels
Datetime Datetime data dtype Frequency DateOffsets good first issue Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@lostella
Copy link
Contributor

lostella commented Jul 2, 2019

Code Sample, a copy-pastable example if possible

ts = pd.Timestamp("2019-01-01", freq="M")
ts1 = ts + 1 * ts.freq
print(ts1.freq)

Problem description

There seem to be a problem when a new pd.Timestamp is constructed by adding a multiple of the frequency to an initial timestamp: when the frequency is "M" or "W", then the frequency information is lost in the resulting timestamp.

I'm not sure if this is intended behaviour (for some reason), but it seems to be inconsistent across frequencies.

Expected Output

<MonthEnd>

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

INSTALLED VERSIONS

commit: None

pandas: 0.24.2
pytest: None
pip: 19.1.1
setuptools: 41.0.1
Cython: None
numpy: 1.16.4
scipy: None
pyarrow: None
xarray: None
IPython: 7.6.0
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@mroeschke
Copy link
Member

This looks to be working on master:

In [3]: pd.__version__
Out[3]: '0.25.0.dev0+872.gc407b7308'

In [4]: ts = pd.Timestamp("2019-01-01", freq="M")
   ...: ts1 = ts + 1 * ts.freq

In [5]: ts1.freq
Out[5]: <MonthEnd>

If you'd like to add a regression test for this case, I'd be much appreciated.

@mroeschke mroeschke added Frequency DateOffsets Needs Tests Unit test(s) needed to prevent regressions Datetime Datetime data dtype good first issue labels Jul 2, 2019
@lostella
Copy link
Contributor Author

lostella commented Jul 2, 2019

@mroeschke any suggestion on where a test for this would best fit?

@mroeschke
Copy link
Member

pandas/tests/scalar/timestamp/test_arithmetic.py

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants