@@ -8718,6 +8718,13 @@ def tz_localize(self, tz, axis=0, level=None, copy=True,
87188718 copy : boolean, default True
87198719 Also make a copy of the underlying data
87208720 ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise'
8721+ When clocks moved backward due to DST, ambiguous times may arise.
8722+ For example in Central European Time (UTC+01), when going from
8723+ 03:00 DST to 02:00 non-DST, 02:30:00 local time occurs both at
8724+ 00:30:00 UTC and at 01:30:00 UTC. In such a situation, the
8725+ `ambiguous` parameter dictates how ambiguous times should be
8726+ handled.
8727+
87218728 - 'infer' will attempt to infer fall dst-transition hours based on
87228729 order
87238730 - bool-ndarray where True signifies a DST time, False designates
@@ -8745,6 +8752,52 @@ def tz_localize(self, tz, axis=0, level=None, copy=True,
87458752 ------
87468753 TypeError
87478754 If the TimeSeries is tz-aware and tz is not None.
8755+
8756+ Examples
8757+ --------
8758+
8759+ Localize local times:
8760+
8761+ >>> s = pd.Series([1],
8762+ ... index=pd.DatetimeIndex(['2018-09-15 01:30:00']))
8763+ >>> s.tz_localize('CET')
8764+ 2018-09-15 01:30:00+02:00 1
8765+ dtype: int64
8766+
8767+ Be careful with DST changes. When there is sequential data, pandas
8768+ can infer the DST time:
8769+
8770+ >>> s = pd.Series(range(7), index=pd.DatetimeIndex([
8771+ ... '2018-10-28 01:30:00',
8772+ ... '2018-10-28 02:00:00',
8773+ ... '2018-10-28 02:30:00',
8774+ ... '2018-10-28 02:00:00',
8775+ ... '2018-10-28 02:30:00',
8776+ ... '2018-10-28 03:00:00',
8777+ ... '2018-10-28 03:30:00']))
8778+ >>> s.tz_localize('CET', ambiguous='infer')
8779+ 2018-10-28 01:30:00+02:00 0
8780+ 2018-10-28 02:00:00+02:00 1
8781+ 2018-10-28 02:30:00+02:00 2
8782+ 2018-10-28 02:00:00+01:00 3
8783+ 2018-10-28 02:30:00+01:00 4
8784+ 2018-10-28 03:00:00+01:00 5
8785+ 2018-10-28 03:30:00+01:00 6
8786+ dtype: int64
8787+
8788+ In some cases, inferring the DST is impossible. In such cases, you can
8789+ pass an ndarray to the ambiguous parameter to set the DST explicitly
8790+
8791+ >>> s = pd.Series(range(3), index=pd.DatetimeIndex([
8792+ ... '2018-10-28 01:20:00',
8793+ ... '2018-10-28 02:36:00',
8794+ ... '2018-10-28 03:46:00']))
8795+ >>> s.tz_localize('CET', ambiguous=np.array([True, True, False]))
8796+ 2018-10-28 01:20:00+02:00 0
8797+ 2018-10-28 02:36:00+02:00 1
8798+ 2018-10-28 03:46:00+01:00 2
8799+ dtype: int64
8800+
87488801 """
87498802 if nonexistent not in ('raise' , 'NaT' , 'shift' ):
87508803 raise ValueError ("The nonexistent argument must be one of 'raise',"
0 commit comments