@@ -1513,17 +1513,21 @@ Ambiguous Times when Localizing
1513
1513
In some cases, localize cannot determine the DST and non-DST hours when there are
1514
1514
duplicates. This often happens when reading files or database records that simply
1515
1515
duplicate the hours. Passing ``ambiguous='infer' `` (``infer_dst `` argument in prior
1516
- releases) into ``tz_localize `` will attempt to determine the right offset.
1516
+ releases) into ``tz_localize `` will attempt to determine the right offset. Below
1517
+ the top example will fail as it contains ambiguous times and the bottom will
1518
+ infer the right offset.
1517
1519
1518
1520
.. ipython :: python
1519
1521
:okexcept:
1520
1522
1521
1523
rng_hourly = DatetimeIndex([' 11/06/2011 00:00' , ' 11/06/2011 01:00' ,
1522
1524
' 11/06/2011 01:00' , ' 11/06/2011 02:00' ,
1523
1525
' 11/06/2011 03:00' ])
1524
- rng_hourly.tz_localize(' US/Eastern' )
1526
+
1527
+ # This will fail as there are ambiguous times
1528
+ rng_hourly.tz_localize(' US/Eastern' )
1525
1529
rng_hourly_eastern = rng_hourly.tz_localize(' US/Eastern' , ambiguous = ' infer' )
1526
- rng_hourly_eastern.values
1530
+ rng_hourly_eastern.tolist()
1527
1531
1528
1532
In addition to 'infer', there are several other arguments supported. Passing
1529
1533
an array-like of bools or 0s/1s where True represents a DST hour and False a
@@ -1536,8 +1540,8 @@ constructor as well as ``tz_localize``.
1536
1540
.. ipython :: python
1537
1541
1538
1542
rng_hourly_dst = np.array([1 , 1 , 0 , 0 , 0 ])
1539
- rng_hourly.tz_localize(' US/Eastern' , ambiguous = rng_hourly_dst).values
1540
- rng_hourly.tz_localize(' US/Eastern' , ambiguous = ' NaT' ).values
1543
+ rng_hourly.tz_localize(' US/Eastern' , ambiguous = rng_hourly_dst).tolist()
1544
+ rng_hourly.tz_localize(' US/Eastern' , ambiguous = ' NaT' ).tolist()
1541
1545
1542
1546
didx = DatetimeIndex(start = ' 2014-08-01 09:00' , freq = ' H' , periods = 10 , tz = ' US/Eastern' )
1543
1547
didx
0 commit comments