17
17
from pytz import NonExistentTimeError
18
18
19
19
import pandas .util .testing as tm
20
- from pandas .util .testing import assert_frame_equal , set_timezone
20
+ from pandas .util .testing import (assert_frame_equal , assert_series_equal ,
21
+ set_timezone )
21
22
from pandas .compat import lrange , zip
22
23
23
24
try :
@@ -535,6 +536,44 @@ def test_ambiguous_nat(self):
535
536
# right is datetime64[ns, tzfile('/usr/share/zoneinfo/US/Eastern')]
536
537
self .assert_numpy_array_equal (di_test .values , localized .values )
537
538
539
+ def test_ambiguous_bool (self ):
540
+ # make sure that we are correctly accepting bool values as ambiguous
541
+
542
+ # gh-14402
543
+ t = Timestamp ('2015-11-01 01:00:03' )
544
+ expected0 = Timestamp ('2015-11-01 01:00:03-0500' , tz = 'US/Central' )
545
+ expected1 = Timestamp ('2015-11-01 01:00:03-0600' , tz = 'US/Central' )
546
+
547
+ def f ():
548
+ t .tz_localize ('US/Central' )
549
+ self .assertRaises (pytz .AmbiguousTimeError , f )
550
+
551
+ result = t .tz_localize ('US/Central' , ambiguous = True )
552
+ self .assertEqual (result , expected0 )
553
+
554
+ result = t .tz_localize ('US/Central' , ambiguous = False )
555
+ self .assertEqual (result , expected1 )
556
+
557
+ s = Series ([t ])
558
+ expected0 = Series ([expected0 ])
559
+ expected1 = Series ([expected1 ])
560
+
561
+ def f ():
562
+ s .dt .tz_localize ('US/Central' )
563
+ self .assertRaises (pytz .AmbiguousTimeError , f )
564
+
565
+ result = s .dt .tz_localize ('US/Central' , ambiguous = True )
566
+ assert_series_equal (result , expected0 )
567
+
568
+ result = s .dt .tz_localize ('US/Central' , ambiguous = [True ])
569
+ assert_series_equal (result , expected0 )
570
+
571
+ result = s .dt .tz_localize ('US/Central' , ambiguous = False )
572
+ assert_series_equal (result , expected1 )
573
+
574
+ result = s .dt .tz_localize ('US/Central' , ambiguous = [False ])
575
+ assert_series_equal (result , expected1 )
576
+
538
577
def test_nonexistent_raise_coerce (self ):
539
578
# See issue 13057
540
579
from pytz .exceptions import NonExistentTimeError
@@ -629,14 +668,14 @@ def test_localized_at_time_between_time(self):
629
668
result = ts_local .at_time (time (10 , 0 ))
630
669
expected = ts .at_time (time (10 , 0 )).tz_localize (self .tzstr (
631
670
'US/Eastern' ))
632
- tm . assert_series_equal (result , expected )
671
+ assert_series_equal (result , expected )
633
672
self .assertTrue (self .cmptz (result .index .tz , self .tz ('US/Eastern' )))
634
673
635
674
t1 , t2 = time (10 , 0 ), time (11 , 0 )
636
675
result = ts_local .between_time (t1 , t2 )
637
676
expected = ts .between_time (t1 ,
638
677
t2 ).tz_localize (self .tzstr ('US/Eastern' ))
639
- tm . assert_series_equal (result , expected )
678
+ assert_series_equal (result , expected )
640
679
self .assertTrue (self .cmptz (result .index .tz , self .tz ('US/Eastern' )))
641
680
642
681
def test_string_index_alias_tz_aware (self ):
@@ -723,7 +762,7 @@ def test_frame_no_datetime64_dtype(self):
723
762
result = df .get_dtype_counts ().sort_index ()
724
763
expected = Series ({'datetime64[ns]' : 2 ,
725
764
str (tz_expected ): 2 }).sort_index ()
726
- tm . assert_series_equal (result , expected )
765
+ assert_series_equal (result , expected )
727
766
728
767
def test_hongkong_tz_convert (self ):
729
768
# #1673
@@ -1324,7 +1363,7 @@ def test_append_aware(self):
1324
1363
exp_index = DatetimeIndex (['2011-01-01 01:00' , '2011-01-01 02:00' ],
1325
1364
tz = 'US/Eastern' )
1326
1365
exp = Series ([1 , 2 ], index = exp_index )
1327
- self . assert_series_equal (ts_result , exp )
1366
+ assert_series_equal (ts_result , exp )
1328
1367
self .assertEqual (ts_result .index .tz , rng1 .tz )
1329
1368
1330
1369
rng1 = date_range ('1/1/2011 01:00' , periods = 1 , freq = 'H' , tz = 'UTC' )
@@ -1336,7 +1375,7 @@ def test_append_aware(self):
1336
1375
exp_index = DatetimeIndex (['2011-01-01 01:00' , '2011-01-01 02:00' ],
1337
1376
tz = 'UTC' )
1338
1377
exp = Series ([1 , 2 ], index = exp_index )
1339
- self . assert_series_equal (ts_result , exp )
1378
+ assert_series_equal (ts_result , exp )
1340
1379
utc = rng1 .tz
1341
1380
self .assertEqual (utc , ts_result .index .tz )
1342
1381
@@ -1352,7 +1391,7 @@ def test_append_aware(self):
1352
1391
exp_index = Index ([Timestamp ('1/1/2011 01:00' , tz = 'US/Eastern' ),
1353
1392
Timestamp ('1/1/2011 02:00' , tz = 'US/Central' )])
1354
1393
exp = Series ([1 , 2 ], index = exp_index )
1355
- self . assert_series_equal (ts_result , exp )
1394
+ assert_series_equal (ts_result , exp )
1356
1395
1357
1396
def test_append_dst (self ):
1358
1397
rng1 = date_range ('1/1/2016 01:00' , periods = 3 , freq = 'H' ,
@@ -1368,7 +1407,7 @@ def test_append_dst(self):
1368
1407
'2016-08-01 02:00' , '2016-08-01 03:00' ],
1369
1408
tz = 'US/Eastern' )
1370
1409
exp = Series ([1 , 2 , 3 , 10 , 11 , 12 ], index = exp_index )
1371
- tm . assert_series_equal (ts_result , exp )
1410
+ assert_series_equal (ts_result , exp )
1372
1411
self .assertEqual (ts_result .index .tz , rng1 .tz )
1373
1412
1374
1413
def test_append_aware_naive (self ):
@@ -1429,7 +1468,7 @@ def test_arith_utc_convert(self):
1429
1468
expected = uts1 + uts2
1430
1469
1431
1470
self .assertEqual (result .index .tz , pytz .UTC )
1432
- tm . assert_series_equal (result , expected )
1471
+ assert_series_equal (result , expected )
1433
1472
1434
1473
def test_intersection (self ):
1435
1474
rng = date_range ('1/1/2011' , periods = 100 , freq = 'H' , tz = 'utc' )
0 commit comments