@@ -2392,16 +2392,56 @@ def test_dt_tz_localize_none():
2392
2392
2393
2393
2394
2394
@pytest .mark .parametrize ("unit" , ["us" , "ns" ])
2395
- def test_dt_tz_localize (unit ):
2395
+ def test_dt_tz_localize (unit , request ):
2396
+ if is_platform_windows () and is_ci_environment ():
2397
+ request .node .add_marker (
2398
+ pytest .mark .xfail (
2399
+ raises = pa .ArrowInvalid ,
2400
+ reason = (
2401
+ "TODO: Set ARROW_TIMEZONE_DATABASE environment variable "
2402
+ "on CI to path to the tzdata for pyarrow."
2403
+ ),
2404
+ )
2405
+ )
2396
2406
ser = pd .Series (
2397
2407
[datetime (year = 2023 , month = 1 , day = 2 , hour = 3 ), None ],
2398
2408
dtype = ArrowDtype (pa .timestamp (unit )),
2399
2409
)
2400
2410
result = ser .dt .tz_localize ("US/Pacific" )
2401
- expected = pd .Series (
2402
- [datetime (year = 2023 , month = 1 , day = 2 , hour = 3 ), None ],
2403
- dtype = ArrowDtype (pa .timestamp (unit , "US/Pacific" )),
2411
+ exp_data = pa .array (
2412
+ [datetime (year = 2023 , month = 1 , day = 2 , hour = 3 ), None ], type = pa .timestamp (unit )
2413
+ )
2414
+ exp_data = pa .compute .assume_timezone (exp_data , "US/Pacific" )
2415
+ expected = pd .Series (ArrowExtensionArray (exp_data ))
2416
+ tm .assert_series_equal (result , expected )
2417
+
2418
+
2419
+ @pytest .mark .parametrize (
2420
+ "nonexistent, exp_date" ,
2421
+ [
2422
+ ["shift_forward" , datetime (year = 2023 , month = 3 , day = 12 , hour = 3 )],
2423
+ ["shift_backward" , pd .Timestamp ("2023-03-12 01:59:59.999999999" )],
2424
+ ],
2425
+ )
2426
+ def test_dt_tz_localize_nonexistent (nonexistent , exp_date , request ):
2427
+ if is_platform_windows () and is_ci_environment ():
2428
+ request .node .add_marker (
2429
+ pytest .mark .xfail (
2430
+ raises = pa .ArrowInvalid ,
2431
+ reason = (
2432
+ "TODO: Set ARROW_TIMEZONE_DATABASE environment variable "
2433
+ "on CI to path to the tzdata for pyarrow."
2434
+ ),
2435
+ )
2436
+ )
2437
+ ser = pd .Series (
2438
+ [datetime (year = 2023 , month = 3 , day = 12 , hour = 2 , minute = 30 ), None ],
2439
+ dtype = ArrowDtype (pa .timestamp ("ns" )),
2404
2440
)
2441
+ result = ser .dt .tz_localize ("US/Pacific" , nonexistent = nonexistent )
2442
+ exp_data = pa .array ([exp_date , None ], type = pa .timestamp ("ns" ))
2443
+ exp_data = pa .compute .assume_timezone (exp_data , "US/Pacific" )
2444
+ expected = pd .Series (ArrowExtensionArray (exp_data ))
2405
2445
tm .assert_series_equal (result , expected )
2406
2446
2407
2447
0 commit comments