Skip to content

Commit 5e1b8cc

Browse files
committed
compare whole timestamp strings on windows
1 parent 6712f97 commit 5e1b8cc

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

python/pyarrow/tests/test_compute.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,15 +2362,21 @@ def test_strptime():
23622362
assert got == pa.array([None, None, None], type=pa.timestamp('s'))
23632363

23642364

2365-
def _check_all_end_with_offset(arr):
2365+
def _compare_strftime_windows_timezones(result, expected):
23662366
# TODO(GH-48767): On Windows, std::chrono returns GMT offset
23672367
# instead of timezone abbreviations (e.g. "CET")
23682368
# https://github.com/apache/arrow/issues/48767
23692369

2370-
ends_with_offset = pc.match_substring_regex(arr, "(UTC|GMT[+-][0-9]+)$")
2370+
p = "(UTC|GMT[+-][0-9]+)$"
2371+
2372+
ends_with_offset = pc.match_substring_regex(result, p)
23712373
all_end_with_offset = pc.all(ends_with_offset, skip_nulls=True).as_py()
23722374
assert all_end_with_offset, "All timezone values should be GMT offset format or UTC" \
2373-
f"\nActual: {arr}"
2375+
f"\nActual: {result}"
2376+
2377+
result_substring = pc.replace_substring_regex(result, pattern=p, replacement="")
2378+
assert expected.starts_with(
2379+
result_substring), f"Expected: {expected}, \nActual: {result} \n Note: tz suffix is not being compared"
23742380

23752381

23762382
@pytest.mark.pandas
@@ -2395,11 +2401,7 @@ def test_strftime():
23952401
# cast to the same type as result to ignore string vs large_string
23962402
expected = pa.array(ts.strftime(fmt)).cast(result.type)
23972403
if sys.platform == "win32" and fmt == "%Z":
2398-
_check_all_end_with_offset(result)
2399-
pattern = "(UTC|GMT[+-][0-9]+)$"
2400-
result = pc.replace_substring_regex(
2401-
result, pattern=pattern, replacement="")
2402-
assert expected.starts_with(result)
2404+
_compare_strftime_windows_timezones(result, expected)
24032405
else:
24042406
assert result.equals(expected)
24052407

@@ -2416,10 +2418,7 @@ def test_strftime():
24162418
result = pc.strftime(tsa, options=pc.StrftimeOptions(fmt + "%Z"))
24172419
expected = pa.array(ts.strftime(fmt + "%Z")).cast(result.type)
24182420
if sys.platform == "win32":
2419-
_check_all_end_with_offset(result)
2420-
pattern = "(UTC|GMT[+-][0-9]+)$"
2421-
result = pc.replace_substring_regex(result, pattern=pattern, replacement="")
2422-
assert expected.starts_with(result)
2421+
_compare_strftime_windows_timezones(result, expected)
24232422
else:
24242423
assert result.equals(expected)
24252424

0 commit comments

Comments
 (0)