Skip to content

Commit 450f051

Browse files
authored
DOC: Slight clarification regarding date_range and timezones (pandas-dev#49764)
If a timezone-aware datetime-like gets passed, it's timezone gets used as expected.
1 parent be79267 commit 450f051

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pandas/core/indexes/datetimes.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ def date_range(
849849
tz : str or tzinfo, optional
850850
Time zone name for returning localized DatetimeIndex, for example
851851
'Asia/Hong_Kong'. By default, the resulting DatetimeIndex is
852-
timezone-naive.
852+
timezone-naive unless timezone-aware datetime-likes are passed.
853853
normalize : bool, default False
854854
Normalize start/end dates to midnight before generating date range.
855855
name : str, default None
@@ -900,6 +900,18 @@ def date_range(
900900
'2018-01-05', '2018-01-06', '2018-01-07', '2018-01-08'],
901901
dtype='datetime64[ns]', freq='D')
902902
903+
Specify timezone-aware `start` and `end`, with the default daily frequency.
904+
905+
>>> pd.date_range(
906+
... start=pd.to_datetime("1/1/2018").tz_localize("Europe/Berlin"),
907+
... end=pd.to_datetime("1/08/2018").tz_localize("Europe/Berlin"),
908+
... )
909+
DatetimeIndex(['2018-01-01 00:00:00+01:00', '2018-01-02 00:00:00+01:00',
910+
'2018-01-03 00:00:00+01:00', '2018-01-04 00:00:00+01:00',
911+
'2018-01-05 00:00:00+01:00', '2018-01-06 00:00:00+01:00',
912+
'2018-01-07 00:00:00+01:00', '2018-01-08 00:00:00+01:00'],
913+
dtype='datetime64[ns, Europe/Berlin]', freq='D')
914+
903915
Specify `start` and `periods`, the number of periods (days).
904916
905917
>>> pd.date_range(start='1/1/2018', periods=8)

0 commit comments

Comments
 (0)