Skip to content

Commit

Permalink
DOC: Update documentation for date_range(), bdate_range(), and interv…
Browse files Browse the repository at this point in the history
…al_range() to include timedelta as a possible data type for the freq parameter (#48631)

* Update documentation for date_range(), bdate_range(), and interval_range() to include timedelta as a possible data type for the freq parameter

* Add test case for date_range construction using datetime.timedelta
  • Loading branch information
gandhis1 authored Sep 20, 2022
1 parent 41ec469 commit abdaea7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ def date_range(
Right bound for generating dates.
periods : int, optional
Number of periods to generate.
freq : str or DateOffset, default 'D'
freq : str, datetime.timedelta, or DateOffset, default 'D'
Frequency strings can have multiples, e.g. '5H'. See
:ref:`here <timeseries.offset_aliases>` for a list of
frequency aliases.
Expand Down Expand Up @@ -1163,7 +1163,7 @@ def bdate_range(
Right bound for generating dates.
periods : int, default None
Number of periods to generate.
freq : str or DateOffset, default 'B' (business daily)
freq : str, datetime.timedelta, or DateOffset, default 'B' (business daily)
Frequency strings can have multiples, e.g. '5H'.
tz : str or None
Time zone name for returning localized DatetimeIndex, for example
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ def interval_range(
Right bound for generating intervals.
periods : int, default None
Number of periods to generate.
freq : numeric, str, or DateOffset, default None
freq : numeric, str, datetime.timedelta, or DateOffset, default None
The length of each interval. Must be consistent with the type of start
and end, e.g. 2 for numeric, or '5H' for datetime-like. Default is 1
for numeric and 'D' for datetime-like.
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/indexes/datetimes/test_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ def test_date_range_businesshour(self):
rng = date_range("2014-07-04 09:00", "2014-07-08 16:00", freq="BH")
tm.assert_index_equal(idx, rng)

def test_date_range_timedelta(self):
start = "2020-01-01"
end = "2020-01-11"
rng1 = date_range(start, end, freq="3D")
rng2 = date_range(start, end, freq=timedelta(days=3))
tm.assert_index_equal(rng1, rng2)

def test_range_misspecified(self):
# GH #1095
msg = (
Expand Down

0 comments on commit abdaea7

Please sign in to comment.