Skip to content

Commit 608bf34

Browse files
DOC: Fix GL08 for pandas.tseries.offsets.Week.is_on_offset (#63927)
1 parent 4f2a1b5 commit 608bf34

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8181
-i "pandas.tseries.offsets.SemiMonthBegin.rule_code GL08" \
8282
-i "pandas.tseries.offsets.SemiMonthEnd.is_on_offset GL08" \
8383
-i "pandas.tseries.offsets.SemiMonthEnd.rule_code GL08" \
84-
-i "pandas.tseries.offsets.Week.is_on_offset GL08" \
8584
-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
8685

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

pandas/_libs/tslibs/offsets.pyx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4897,6 +4897,44 @@ cdef class Week(SingleConstructorOffset):
48974897
return out
48984898

48994899
def is_on_offset(self, dt: datetime) -> bool:
4900+
"""
4901+
Return boolean whether a timestamp intersects with this frequency.
4902+
4903+
This method determines if a given timestamp falls on a valid week offset.
4904+
If a specific weekday is set (via the ``weekday`` parameter), it checks
4905+
whether the timestamp falls on that day. If no weekday is specified,
4906+
all timestamps are considered on the offset. If ``normalize`` is True,
4907+
it also checks that the time component is midnight.
4908+
4909+
Parameters
4910+
----------
4911+
dt : datetime
4912+
Timestamp to check.
4913+
4914+
Returns
4915+
-------
4916+
bool
4917+
True if the timestamp is on the offset, False otherwise.
4918+
4919+
See Also
4920+
--------
4921+
BusinessDay.is_on_offset : Check if timestamp is on a business day.
4922+
DateOffset.is_on_offset : Check if timestamp intersects with frequency.
4923+
4924+
Examples
4925+
--------
4926+
>>> ts = pd.Timestamp(2022, 1, 3) # Monday
4927+
>>> ts.day_name()
4928+
'Monday'
4929+
>>> pd.offsets.Week().is_on_offset(ts)
4930+
True
4931+
4932+
>>> pd.offsets.Week(weekday=0).is_on_offset(ts) # weekday=0 is Monday
4933+
True
4934+
4935+
>>> pd.offsets.Week(weekday=6).is_on_offset(ts) # weekday=6 is Sunday
4936+
False
4937+
"""
49004938
if self.normalize and not _is_normalized(dt):
49014939
return False
49024940
elif self.weekday is None:

0 commit comments

Comments
 (0)