Skip to content

Commit 7319521

Browse files
committed
DOC: Improve DateOffset docstring with constructor and examples (#52431)
1 parent e2bd8e6 commit 7319521

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

pandas/_libs/tslibs/offsets.pyx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,45 @@ class DateOffset(RelativeDeltaOffset, metaclass=OffsetMeta):
16401640
Standard kind of date increment used for a date range.
16411641
16421642
Works exactly like the keyword argument form of relativedelta.
1643+
1644+
Standard base class for defining time based frequency offsets in pandas.
1645+
1646+
DateOffset objects can be added to or subtracted from datetime-like values.
1647+
Subclasses of DateOffset define specific time increments, such as days,
1648+
months, or business days. This class is not typically used directly;
1649+
instead, use subclasses like MonthEnd, BusinessDay, or Hour.
1650+
1651+
Parameters
1652+
----------
1653+
n : int, default 1
1654+
The number of time periods the offset represents.
1655+
normalize : bool, default False
1656+
Whether to normalize the result to midnight.
1657+
**kwds : dict, optional
1658+
Additional keyword arguments handled by subclasses. Examples include:
1659+
months, days, weekday, weekmask, holidays, etc.
1660+
1661+
See Also
1662+
--------
1663+
pandas.tseries.offsets.BusinessDay : Offset representing business days.
1664+
pandas.tseries.offsets.MonthEnd : Offset representing end-of-month dates.
1665+
pandas.date_range : Generate a sequence of dates using an offset.
1666+
pandas.Series.resample : Convert time series to specified frequency.
1667+
1668+
Examples
1669+
--------
1670+
>>> from pandas.tseries.offsets import DateOffset
1671+
>>> import pandas as pd
1672+
>>> ts = pd.Timestamp("2023-01-15")
1673+
>>> ts + DateOffset(months=1)
1674+
Timestamp('2023-02-15 00:00:00')
1675+
1676+
>>> ts - DateOffset(days=10)
1677+
Timestamp('2023-01-05 00:00:00')
1678+
1679+
>>> ts + DateOffset(weekday=0) # Monday
1680+
Timestamp('2023-01-16 00:00:00')
1681+
16431682
Note that the positional argument form of relativedelta is not
16441683
supported. Use of the keyword n is discouraged-- you would be better
16451684
off specifying n in the keywords you use, but regardless it is

0 commit comments

Comments
 (0)