Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
"$BASE_DIR"/scripts/validate_docstrings.py \
--format=actions \
-i ES01 `# For now it is ok if docstrings are missing the extended summary` \
-i "pandas.tseries.offsets.CustomBusinessHour PR02,SA01" \
-i "pandas.tseries.offsets.LastWeekOfMonth.is_on_offset GL08" \
-i "pandas.tseries.offsets.WeekOfMonth.is_on_offset GL08" # There should be no backslash in the final line, please keep this comment in the last ignored function
-i "pandas.tseries.offsets.CustomBusinessHour PR02,SA01" # There should be no backslash in the final line, please keep this comment in the last ignored function

RET=$(($RET + $?)) ; echo $MSG "DONE"

Expand Down
40 changes: 40 additions & 0 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3154,6 +3154,46 @@ cdef class WeekOfMonthMixin(SingleConstructorOffset):
return _shift_day(shifted, to_day - shifted.day)

def is_on_offset(self, dt: datetime) -> bool:
"""
Return boolean whether a timestamp intersects with this frequency.

This method checks if the given timestamp falls on the expected day
of the month for this offset. For WeekOfMonth, this is the specified
weekday of the specified week of the month. For LastWeekOfMonth, this
is the specified weekday of the last week of the month.

Parameters
----------
dt : datetime
Timestamp to check intersection with frequency.

Returns
-------
bool
True if the timestamp is on the offset, False otherwise.

See Also
--------
tseries.offsets.WeekOfMonth : Describes monthly dates in a specific week.
tseries.offsets.LastWeekOfMonth : Describes monthly dates in the last week.

Examples
--------
>>> ts = pd.Timestamp(2022, 1, 3)
>>> ts.day_name()
'Monday'
>>> pd.offsets.WeekOfMonth(week=0, weekday=0).is_on_offset(ts)
True

>>> ts = pd.Timestamp(2022, 1, 10)
>>> ts.day_name()
'Monday'
>>> pd.offsets.WeekOfMonth(week=0, weekday=0).is_on_offset(ts)
False

>>> pd.offsets.WeekOfMonth(week=1, weekday=0).is_on_offset(ts)
True
"""
if self.normalize and not _is_normalized(dt):
return False
return dt.day == self._get_offset_day(dt)
Expand Down
Loading