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