@@ -8718,6 +8718,13 @@ def tz_localize(self, tz, axis=0, level=None, copy=True,
8718
8718
copy : boolean, default True
8719
8719
Also make a copy of the underlying data
8720
8720
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
+
8721
8728
- 'infer' will attempt to infer fall dst-transition hours based on
8722
8729
order
8723
8730
- 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,
8745
8752
------
8746
8753
TypeError
8747
8754
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
+
8748
8801
"""
8749
8802
if nonexistent not in ('raise' , 'NaT' , 'shift' ):
8750
8803
raise ValueError ("The nonexistent argument must be one of 'raise',"
0 commit comments