Skip to content

Commit 610a8ff

Browse files
DOC: Fix GL08 for pandas.tseries.offsets.WeekOfMonth.is_on_offset
1 parent f0161bc commit 610a8ff

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

ci/code_checks.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7070
"$BASE_DIR"/scripts/validate_docstrings.py \
7171
--format=actions \
7272
-i ES01 `# For now it is ok if docstrings are missing the extended summary` \
73-
-i "pandas.tseries.offsets.CustomBusinessHour PR02,SA01" \
74-
-i "pandas.tseries.offsets.LastWeekOfMonth.is_on_offset GL08" \
75-
-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
73+
-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
7674

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

pandas/_libs/tslibs/offsets.pyx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,6 +3154,46 @@ cdef class WeekOfMonthMixin(SingleConstructorOffset):
31543154
return _shift_day(shifted, to_day - shifted.day)
31553155

31563156
def is_on_offset(self, dt: datetime) -> bool:
3157+
"""
3158+
Return boolean whether a timestamp intersects with this frequency.
3159+
3160+
This method checks if the given timestamp falls on the expected day
3161+
of the month for this offset. For WeekOfMonth, this is the specified
3162+
weekday of the specified week of the month. For LastWeekOfMonth, this
3163+
is the specified weekday of the last week of the month.
3164+
3165+
Parameters
3166+
----------
3167+
dt : datetime
3168+
Timestamp to check intersection with frequency.
3169+
3170+
Returns
3171+
-------
3172+
bool
3173+
True if the timestamp is on the offset, False otherwise.
3174+
3175+
See Also
3176+
--------
3177+
tseries.offsets.WeekOfMonth : Describes monthly dates in a specific week.
3178+
tseries.offsets.LastWeekOfMonth : Describes monthly dates in the last week.
3179+
3180+
Examples
3181+
--------
3182+
>>> ts = pd.Timestamp(2022, 1, 3)
3183+
>>> ts.day_name()
3184+
'Monday'
3185+
>>> pd.offsets.WeekOfMonth(week=0, weekday=0).is_on_offset(ts)
3186+
True
3187+
3188+
>>> ts = pd.Timestamp(2022, 1, 10)
3189+
>>> ts.day_name()
3190+
'Monday'
3191+
>>> pd.offsets.WeekOfMonth(week=0, weekday=0).is_on_offset(ts)
3192+
False
3193+
3194+
>>> pd.offsets.WeekOfMonth(week=1, weekday=0).is_on_offset(ts)
3195+
True
3196+
"""
31573197
if self.normalize and not _is_normalized(dt):
31583198
return False
31593199
return dt.day == self._get_offset_day(dt)

0 commit comments

Comments
 (0)