Skip to content
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

BUG: Unexpected results when adding offsets to periods stored in series. #47883

Closed
2 of 3 tasks
asandeep opened this issue Jul 28, 2022 · 2 comments
Closed
2 of 3 tasks
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@asandeep
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd


df = pd.DataFrame({
  "current_period": [pd.Period(year=2022, month=3, freq="2Q-MAR") for _ in range(3)], 
  "offset": list(range(3))
})

  current_period  offset
0         2022Q4       0
1         2022Q4       1
2         2022Q4       2


df.current_period + df.offset

0    2022Q4
1    2023Q1
2    2023Q2
dtype: period[2Q-MAR]


df.apply(lambda r: r.current_period + r.offset, axis=1)

0    2022Q4
1    2023Q2
2    2023Q4
dtype: period[2Q-MAR]

Issue Description

I am storing half-yearly periods in a Dataframe. When some offset values are added to the periods using the offset series stored in same DataFrame, the periods won't shift as expected.

However, iterating over same DF and adding the offset individually returns the correct output.

Expected Behavior

The periods should shift correctly irrespective of how offsets are added.

Installed Versions

INSTALLED VERSIONS

commit : e8093ba
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-41-generic
Version : #44~20.04.1-Ubuntu SMP Fri Jun 24 13:27:29 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_IN
LOCALE : en_IN.ISO8859-1

pandas : 1.4.3
numpy : 1.22.4
pytz : 2022.1
dateutil : 2.8.2
setuptools : 62.1.0
pip : 22.0.4
Cython : None
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.3
jinja2 : 2.11.3
IPython : 8.3.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2022.5.0
gcsfs : None
markupsafe : 2.0.1
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 7.0.0
pyreadstat : None
pyxlsb : None
s3fs : 2022.5.0
scipy : None
snappy : None
sqlalchemy : 1.3.24
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
zstandard : None

@asandeep asandeep added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 28, 2022
@jbrockmendel
Copy link
Member

Can you check on main. This looks similar to something i think was fixed recently.

@asandeep
Copy link
Author

asandeep commented Aug 5, 2022

Hey @jbrockmendel ,

Thanks for your response. I just verified this on main branch as you said and it works as expected.

Marking the issue as closed.

@asandeep asandeep closed this as completed Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants