Skip to content

Commit 794913c

Browse files
BUG: pandas.tseries.frequencies.to_offset() raises ValueError when parsing a LastWeekOfMonth frequency string (#59245)
* add LastWeekOfMonth to prefix_mapping * update whatsnew
1 parent 40c63d8 commit 794913c

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ Datetimelike
503503
- Bug in :func:`date_range` where the last valid timestamp would sometimes not be produced (:issue:`56134`)
504504
- Bug in :func:`date_range` where using a negative frequency value would not include all points between the start and end values (:issue:`56382`)
505505
- Bug in :func:`tseries.api.guess_datetime_format` would fail to infer time format when "%Y" == "%H%M" (:issue:`57452`)
506+
- Bug in :func:`tseries.frequencies.to_offset` would fail to parse frequency strings starting with "LWOM" (:issue:`59218`)
506507
- Bug in :meth:`Dataframe.agg` with df with missing values resulting in IndexError (:issue:`58810`)
507508
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` does not raise on Custom business days frequencies bigger then "1C" (:issue:`58664`)
508509
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` returning ``False`` on double-digit frequencies (:issue:`58523`)

pandas/_libs/tslibs/offsets.pyx

+1
Original file line numberDiff line numberDiff line change
@@ -4676,6 +4676,7 @@ prefix_mapping = {
46764676
Hour, # 'h'
46774677
Day, # 'D'
46784678
WeekOfMonth, # 'WOM'
4679+
LastWeekOfMonth, # 'LWOM'
46794680
FY5253,
46804681
FY5253Quarter,
46814682
]

pandas/tests/tslibs/test_to_offset.py

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
("2SME-16", offsets.SemiMonthEnd(2, day_of_month=16)),
3232
("2SMS-14", offsets.SemiMonthBegin(2, day_of_month=14)),
3333
("2SMS-15", offsets.SemiMonthBegin(2)),
34+
("LWOM-MON", offsets.LastWeekOfMonth()),
3435
],
3536
)
3637
def test_to_offset(freq_input, expected):

0 commit comments

Comments
 (0)