@@ -345,6 +345,72 @@ def test_dt_namespace_accessor_categorical(self):
345
345
expected = Series ([2017 , 2017 , 2018 , 2018 ], name = "foo" )
346
346
tm .assert_series_equal (result , expected )
347
347
348
+ def test_dt_tz_localize (self , tz_aware_fixture ):
349
+ # GH 27952
350
+ tz = tz_aware_fixture
351
+ datetimes = pd .Series (
352
+ ["2019-01-01" , "2019-01-01" , "2019-01-02" ], dtype = "datetime64[ns]"
353
+ )
354
+ categorical = datetimes .astype ("category" )
355
+ result = categorical .dt .tz_localize (tz )
356
+ expected = datetimes .dt .tz_localize (tz )
357
+ tm .assert_series_equal (result , expected )
358
+
359
+ def test_dt_tz_convert (self , tz_aware_fixture ):
360
+ # GH 27952
361
+ tz = tz_aware_fixture
362
+ datetimes = pd .Series (
363
+ ["2019-01-01" , "2019-01-01" , "2019-01-02" ], dtype = "datetime64[ns, MET]"
364
+ )
365
+ categorical = datetimes .astype ("category" )
366
+ result = categorical .dt .tz_convert (tz )
367
+ expected = datetimes .dt .tz_convert (tz )
368
+ tm .assert_series_equal (result , expected )
369
+
370
+ @pytest .mark .parametrize ("accessor" , ["year" , "month" , "day" ])
371
+ def test_dt_other_accessors (self , accessor ):
372
+ # GH 27952
373
+ datetimes = pd .Series (
374
+ ["2018-01-01" , "2018-01-01" , "2019-01-02" ], dtype = "datetime64[ns]"
375
+ )
376
+ categorical = datetimes .astype ("category" )
377
+ result = getattr (categorical .dt , accessor )
378
+ expected = getattr (datetimes .dt , accessor )
379
+ tm .assert_series_equal (result , expected )
380
+
381
+ def test_dt_tz_localize (self , tz_aware_fixture ):
382
+ # GH 27952
383
+ tz = tz_aware_fixture
384
+ datetimes = pd .Series (
385
+ ["2019-01-01" , "2019-01-01" , "2019-01-02" ], dtype = "datetime64[ns]"
386
+ )
387
+ categorical = datetimes .astype ("category" )
388
+ result = categorical .dt .tz_localize (tz )
389
+ expected = datetimes .dt .tz_localize (tz )
390
+ tm .assert_series_equal (result , expected )
391
+
392
+ def test_dt_tz_convert (self , tz_aware_fixture ):
393
+ # GH 27952
394
+ tz = tz_aware_fixture
395
+ datetimes = pd .Series (
396
+ ["2019-01-01" , "2019-01-01" , "2019-01-02" ], dtype = "datetime64[ns, MET]"
397
+ )
398
+ categorical = datetimes .astype ("category" )
399
+ result = categorical .dt .tz_convert (tz )
400
+ expected = datetimes .dt .tz_convert (tz )
401
+ tm .assert_series_equal (result , expected )
402
+
403
+ @pytest .mark .parametrize ("accessor" , ["year" , "month" , "day" ])
404
+ def test_dt_other_accessors (self , accessor ):
405
+ # GH 27952
406
+ datetimes = pd .Series (
407
+ ["2018-01-01" , "2018-01-01" , "2019-01-02" ], dtype = "datetime64[ns]"
408
+ )
409
+ categorical = datetimes .astype ("category" )
410
+ result = getattr (categorical .dt , accessor )
411
+ expected = getattr (datetimes .dt , accessor )
412
+ tm .assert_series_equal (result , expected )
413
+
348
414
def test_dt_accessor_no_new_attributes (self ):
349
415
# https://github.com/pandas-dev/pandas/issues/10673
350
416
s = Series (date_range ("20130101" , periods = 5 , freq = "D" ))
0 commit comments