Skip to content

Commit 98a760f

Browse files
committed
DOC: add missing parameters to offsets classes: Second, Hour and Day
1 parent 4357621 commit 98a760f

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

pandas/_libs/tslibs/offsets.pyx

+115
Original file line numberDiff line numberDiff line change
@@ -1089,27 +1089,142 @@ cdef class Tick(SingleConstructorOffset):
10891089

10901090

10911091
cdef class Day(Tick):
1092+
"""
1093+
Offset ``n`` days.
1094+
1095+
Parameters
1096+
----------
1097+
n : int, default 1
1098+
The number of days represented.
1099+
1100+
See Also
1101+
--------
1102+
:class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment.
1103+
1104+
Examples
1105+
--------
1106+
You can use the parameter ``n`` to represent a shift of n days.
1107+
>>> from pandas.tseries.offsets import Day
1108+
>>> ts = pd.Timestamp(2022, 12, 9, 15)
1109+
>>> ts.strftime('%a %d %b %Y %H:%M')
1110+
'Fri 09 Dec 2022 15:00'
1111+
1112+
>>> (ts + Day()).strftime('%a %d %b %Y %H:%M')
1113+
'Sat 10 Dec 2022 15:00'
1114+
>>> (ts - Day(4)).strftime('%a %d %b %Y %H:%M')
1115+
'Mon 05 Dec 2022 15:00'
1116+
1117+
>>> (ts + Day(-4)).strftime('%a %d %b %Y %H:%M')
1118+
'Mon 05 Dec 2022 15:00'
1119+
"""
10921120
_nanos_inc = 24 * 3600 * 1_000_000_000
10931121
_prefix = "D"
10941122
_period_dtype_code = PeriodDtypeCode.D
10951123
_creso = NPY_DATETIMEUNIT.NPY_FR_D
10961124

10971125

10981126
cdef class Hour(Tick):
1127+
"""
1128+
Offset ``n`` hours.
1129+
1130+
Parameters
1131+
----------
1132+
n : int, default 1
1133+
The number of hours represented.
1134+
1135+
See Also
1136+
--------
1137+
:class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment.
1138+
1139+
Examples
1140+
--------
1141+
You can use the parameter ``n`` to represent a shift of n hours.
1142+
1143+
>>> from pandas.tseries.offsets import Hour
1144+
>>> ts = pd.Timestamp(2022, 12, 9, 15)
1145+
>>> ts.strftime('%a %d %b %Y %H:%M')
1146+
'Fri 09 Dec 2022 15:00'
1147+
1148+
>>> (ts + Hour()).strftime('%a %d %b %Y %H:%M')
1149+
'Fri 09 Dec 2022 16:00'
1150+
>>> (ts - Hour(4)).strftime('%a %d %b %Y %H:%M')
1151+
'Fri 09 Dec 2022 11:00'
1152+
1153+
>>> (ts + Hour(-4)).strftime('%a %d %b %Y %H:%M')
1154+
'Fri 09 Dec 2022 11:00'
1155+
"""
10991156
_nanos_inc = 3600 * 1_000_000_000
11001157
_prefix = "H"
11011158
_period_dtype_code = PeriodDtypeCode.H
11021159
_creso = NPY_DATETIMEUNIT.NPY_FR_h
11031160

11041161

11051162
cdef class Minute(Tick):
1163+
"""
1164+
Offset ``n`` minutes.
1165+
1166+
Parameters
1167+
----------
1168+
n : int, default 1
1169+
The number of minutes represented.
1170+
1171+
See Also
1172+
--------
1173+
:class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment.
1174+
1175+
Examples
1176+
--------
1177+
You can use the parameter ``n`` to represent a shift of n minutes.
1178+
1179+
>>> from pandas.tseries.offsets import Minute
1180+
>>> ts = pd.Timestamp(2022, 12, 9, 15)
1181+
>>> ts.strftime('%a %d %b %Y %H:%M:%S')
1182+
'Fri 09 Dec 2022 15:00:00'
1183+
1184+
>>> (ts + Minute(n=10)).strftime('%a %d %b %Y %H:%M:%S')
1185+
'Fri 09 Dec 2022 15:10:00'
1186+
>>> (ts - Minute(n=10)).strftime('%a %d %b %Y %H:%M:%S')
1187+
'Fri 09 Dec 2022 14:50:00'
1188+
1189+
>>> (ts + Minute(n=-10)).strftime('%a %d %b %Y %H:%M:%S')
1190+
'Fri 09 Dec 2022 14:50:00'
1191+
"""
11061192
_nanos_inc = 60 * 1_000_000_000
11071193
_prefix = "T"
11081194
_period_dtype_code = PeriodDtypeCode.T
11091195
_creso = NPY_DATETIMEUNIT.NPY_FR_m
11101196

11111197

11121198
cdef class Second(Tick):
1199+
"""
1200+
Offset ``n`` seconds.
1201+
1202+
Parameters
1203+
----------
1204+
n : int, default 1
1205+
The number of seconds represented.
1206+
1207+
See Also
1208+
--------
1209+
:class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment.
1210+
1211+
Examples
1212+
--------
1213+
You can use the parameter ``n`` to represent a shift of n seconds.
1214+
1215+
>>> from pandas.tseries.offsets import Second
1216+
>>> ts = pd.Timestamp(2022, 12, 9, 15)
1217+
>>> ts.strftime('%a %d %b %Y %H:%M:%S')
1218+
'Fri 09 Dec 2022 15:00:00'
1219+
1220+
>>> (ts + Second(n=10)).strftime('%a %d %b %Y %H:%M:%S')
1221+
'Fri 09 Dec 2022 15:00:10'
1222+
>>> (ts - Second(n=10)).strftime('%a %d %b %Y %H:%M:%S')
1223+
'Fri 09 Dec 2022 14:59:50'
1224+
1225+
>>> (ts + Second(n=-10)).strftime('%a %d %b %Y %H:%M:%S')
1226+
'Fri 09 Dec 2022 14:59:50'
1227+
"""
11131228
_nanos_inc = 1_000_000_000
11141229
_prefix = "S"
11151230
_period_dtype_code = PeriodDtypeCode.S

0 commit comments

Comments
 (0)