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: pandas.tseries.frequencies.to_offset() raises ValueError when parsing a LastWeekOfMonth frequency string #59218

Closed
2 of 3 tasks
ypsah opened this issue Jul 9, 2024 · 2 comments · Fixed by #59245
Closed
2 of 3 tasks
Assignees
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@ypsah
Copy link

ypsah commented Jul 9, 2024

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
pd.tseries.frequencies.to_offset(pd.offsets.LastWeekOfMonth().freqstr)

Issue Description

The code above raises the following exception:

Traceback (most recent call last):
  File "offsets.pyx", line 4776, in pandas._libs.tslibs.offsets._get_offset
KeyError: 'LWOM'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "offsets.pyx", line 4946, in pandas._libs.tslibs.offsets.to_offset
  File "offsets.pyx", line 4782, in pandas._libs.tslibs.offsets._get_offset
ValueError: Invalid frequency: LWOM-MON, failed to parse with error message: KeyError('LWOM')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "offsets.pyx", line 4791, in pandas._libs.tslibs.offsets.to_offset
  File "offsets.pyx", line 4954, in pandas._libs.tslibs.offsets.to_offset
ValueError: Invalid frequency: LWOM-MON, failed to parse with error message: ValueError("Invalid frequency: LWOM-MON, failed to parse with error message: KeyError('LWOM')")

I've tracked down the issue to LastWeekOfMonth not being present here:

prefix_mapping = {
.

Expected Behavior

pd.tseries.frequencies.to_offset can parse any LastWeekOfMonth frequency string.

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.12.4.final.0
python-bits : 64
OS : Linux
OS-release : 6.9.7-arch1-1
Version : #1 SMP PREEMPT_DYNAMIC Fri, 28 Jun 2024 04:32:50 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.2
numpy : 2.0.0
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : None
pip : 24.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
None

@ypsah ypsah added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 9, 2024
@aram-cinnamon
Copy link
Contributor

take

@ypsah
Copy link
Author

ypsah commented Jul 16, 2024

Thanks

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
2 participants