You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pandas/tseries/offsets.py
+97-4
Original file line number
Diff line number
Diff line change
@@ -204,8 +204,7 @@ def __add__(date):
204
204
normalize : bool, default False
205
205
Whether to round the result of a DateOffset addition down to the
206
206
previous midnight.
207
-
**kwds
208
-
Temporal parameter that add to or replace the offset value.
207
+
**kwds : Temporal parameter that add to or replace the offset value.
209
208
210
209
Parameters that **add** to the offset (like Timedelta):
211
210
@@ -231,18 +230,21 @@ def __add__(date):
231
230
- microsecond
232
231
- nanosecond
233
232
233
+
.
234
+
234
235
See Also
235
236
--------
236
-
dateutil.relativedelta.relativedelta
237
+
dateutil.relativedelta.relativedelta : The relativedelta type is designed to be applied to an existing datetime an can replace specific components of that datetime, or represents an interval of time.
237
238
238
239
Examples
239
240
--------
241
+
>>> from pandas.tseries.offsets import DateOffset
240
242
>>> ts = pd.Timestamp('2017-01-01 09:10:11')
241
243
>>> ts + DateOffset(months=3)
242
244
Timestamp('2017-04-01 09:10:11')
243
245
244
246
>>> ts = pd.Timestamp('2017-01-01 09:10:11')
245
-
>>> ts + DateOffset(month=3)
247
+
>>> ts + DateOffset(months=2)
246
248
Timestamp('2017-03-01 09:10:11')
247
249
"""
248
250
@@ -471,6 +473,97 @@ def nanos(self):
471
473
472
474
473
475
classSingleConstructorOffset(DateOffset):
476
+
"""
477
+
Standard kind of date increment used for a date range.
478
+
479
+
Works exactly like relativedelta in terms of the keyword args you
480
+
pass in, use of the keyword n is discouraged-- you would be better
481
+
off specifying n in the keywords you use, but regardless it is
482
+
there for you. n is needed for DateOffset subclasses.
483
+
484
+
DateOffset work as follows. Each offset specify a set of dates
485
+
that conform to the DateOffset. For example, Bday defines this
486
+
set to be the set of dates that are weekdays (M-F). To test if a
487
+
date is in the set of a DateOffset dateOffset we can use the
488
+
onOffset method: dateOffset.onOffset(date).
489
+
490
+
If a date is not on a valid date, the rollback and rollforward
491
+
methods can be used to roll the date to the nearest valid date
492
+
before/after the date.
493
+
494
+
DateOffsets can be created to move dates forward a given number of
495
+
valid dates. For example, Bday(2) can be added to a date to move
496
+
it two business days forward. If the date does not start on a
497
+
valid date, first it is moved to a valid date. Thus pseudo code
498
+
is:
499
+
500
+
def __add__(date):
501
+
date = rollback(date) # does nothing if date is valid
502
+
return date + <n number of periods>
503
+
504
+
When a date offset is created for a negative number of periods,
505
+
the date is first rolled forward. The pseudo code is:
506
+
507
+
def __add__(date):
508
+
date = rollforward(date) # does nothing is date is valid
509
+
return date + <n number of periods>
510
+
511
+
Zero presents a problem. Should it roll forward or back? We
512
+
arbitrarily have it rollforward:
513
+
514
+
date + BDay(0) == BDay.rollforward(date)
515
+
516
+
Since 0 is a bit weird, we suggest avoiding its use.
517
+
518
+
Parameters
519
+
----------
520
+
n : int, default 1
521
+
The number of time periods the offset represents.
522
+
normalize : bool, default False
523
+
Whether to round the result of a DateOffset addition down to the
524
+
previous midnight.
525
+
**kwds : Temporal parameter that add to or replace the offset value.
526
+
527
+
Parameters that **add** to the offset (like Timedelta):
0 commit comments