@@ -472,36 +472,26 @@ def test_categorical(self, method, box, ordered):
472
472
reconstr = box (result_uniques [result_inverse ])
473
473
assert_series_or_index_or_array_or_categorical_equal (reconstr , c )
474
474
475
- def test_datetime64tz_aware (self ):
475
+ @pytest .mark .parametrize ('box' , [Series , Index ])
476
+ @pytest .mark .parametrize ('method' , [lambda x , ** kwargs : x .unique (** kwargs ),
477
+ pd .unique ],
478
+ ids = ['classmethod' , 'toplevel' ])
479
+ def test_datetime64tz_aware (self , method , box ):
476
480
# GH 15939
477
481
478
- result = Series (
479
- Index ([Timestamp ('20160101' , tz = 'US/Eastern' ),
480
- Timestamp ('20160101' , tz = 'US/Eastern' )])).unique ()
481
- expected = DatetimeArray ._from_sequence (np .array ([
482
- Timestamp ('2016-01-01 00:00:00-0500' , tz = "US/Eastern" )
483
- ]))
484
- tm .assert_extension_array_equal (result , expected )
485
-
486
- result = Index ([Timestamp ('20160101' , tz = 'US/Eastern' ),
487
- Timestamp ('20160101' , tz = 'US/Eastern' )]).unique ()
488
- expected = DatetimeIndex (['2016-01-01 00:00:00' ],
489
- dtype = 'datetime64[ns, US/Eastern]' , freq = None )
490
- tm .assert_index_equal (result , expected )
491
-
492
- result = pd .unique (
493
- Series (Index ([Timestamp ('20160101' , tz = 'US/Eastern' ),
494
- Timestamp ('20160101' , tz = 'US/Eastern' )])))
495
- expected = DatetimeArray ._from_sequence (np .array ([
496
- Timestamp ('2016-01-01' , tz = "US/Eastern" ),
497
- ]))
498
- tm .assert_extension_array_equal (result , expected )
499
-
500
- result = pd .unique (Index ([Timestamp ('20160101' , tz = 'US/Eastern' ),
501
- Timestamp ('20160101' , tz = 'US/Eastern' )]))
502
- expected = DatetimeIndex (['2016-01-01 00:00:00' ],
503
- dtype = 'datetime64[ns, US/Eastern]' , freq = None )
504
- tm .assert_index_equal (result , expected )
482
+ ts = Timestamp ('20160101' , tz = 'US/Eastern' )
483
+ obj = box ([ts , ts ])
484
+
485
+ if box == Series :
486
+ expected = DatetimeArray ._from_sequence (np .array ([
487
+ Timestamp ('2016-01-01 00:00:00-0500' , tz = "US/Eastern" )
488
+ ]))
489
+ else : # Index
490
+ expected = DatetimeIndex (['2016-01-01 00:00:00' ],
491
+ dtype = 'datetime64[ns, US/Eastern]' ,
492
+ freq = None )
493
+ result = method (obj )
494
+ assert_series_or_index_or_array_or_categorical_equal (result , expected )
505
495
506
496
def test_order_of_appearance (self ):
507
497
# 9346
@@ -515,20 +505,6 @@ def test_order_of_appearance(self):
515
505
tm .assert_numpy_array_equal (result ,
516
506
np .array ([2 , 1 ], dtype = 'int64' ))
517
507
518
- result = pd .unique (Series ([Timestamp ('20160101' ),
519
- Timestamp ('20160101' )]))
520
- expected = np .array (['2016-01-01T00:00:00.000000000' ],
521
- dtype = 'datetime64[ns]' )
522
- tm .assert_numpy_array_equal (result , expected )
523
-
524
- result = pd .unique (Index (
525
- [Timestamp ('20160101' , tz = 'US/Eastern' ),
526
- Timestamp ('20160101' , tz = 'US/Eastern' )]))
527
- expected = DatetimeIndex (['2016-01-01 00:00:00' ],
528
- dtype = 'datetime64[ns, US/Eastern]' ,
529
- freq = None )
530
- tm .assert_index_equal (result , expected )
531
-
532
508
result = pd .unique (list ('aabc' ))
533
509
expected = np .array (['a' , 'b' , 'c' ], dtype = object )
534
510
tm .assert_numpy_array_equal (result , expected )
0 commit comments