Skip to content

Commit 0a5d1cf

Browse files
authored
CI: catch windows py38 OSError (pandas-dev#37659)
1 parent 8b05fe3 commit 0a5d1cf

File tree

5 files changed

+44
-20
lines changed

5 files changed

+44
-20
lines changed

pandas/_libs/tslibs/tzconversion.pxd

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ from cpython.datetime cimport tzinfo
22
from numpy cimport int64_t
33

44

5-
cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz, bint* fold=*)
5+
cdef int64_t tz_convert_utc_to_tzlocal(
6+
int64_t utc_val, tzinfo tz, bint* fold=*
7+
) except? -1
68
cpdef int64_t tz_convert_from_utc_single(int64_t val, tzinfo tz)
79
cdef int64_t tz_localize_to_utc_single(
810
int64_t val, tzinfo tz, object ambiguous=*, object nonexistent=*

pandas/_libs/tslibs/tzconversion.pyx

+6-2
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,9 @@ cdef inline str _render_tstamp(int64_t val):
355355
# ----------------------------------------------------------------------
356356
# Timezone Conversion
357357

358-
cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz, bint* fold=NULL):
358+
cdef int64_t tz_convert_utc_to_tzlocal(
359+
int64_t utc_val, tzinfo tz, bint* fold=NULL
360+
) except? -1:
359361
"""
360362
Parameters
361363
----------
@@ -549,8 +551,10 @@ cdef inline int64_t _tzlocal_get_offset_components(int64_t val, tzinfo tz,
549551
return int(td.total_seconds() * 1_000_000_000)
550552

551553

554+
# OSError may be thrown by tzlocal on windows at or close to 1970-01-01
555+
# see https://github.com/pandas-dev/pandas/pull/37591#issuecomment-720628241
552556
cdef int64_t _tz_convert_tzlocal_utc(int64_t val, tzinfo tz, bint to_utc=True,
553-
bint* fold=NULL):
557+
bint* fold=NULL) except? -1:
554558
"""
555559
Convert the i8 representation of a datetime from a tzlocal timezone to
556560
UTC, or vice-versa.

pandas/tests/frame/test_reductions.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from datetime import timedelta
22
from decimal import Decimal
33

4+
from dateutil.tz import tzlocal
45
import numpy as np
56
import pytest
67

8+
from pandas.compat import is_platform_windows
79
import pandas.util._test_decorators as td
810

911
import pandas as pd
@@ -1172,6 +1174,12 @@ def test_min_max_dt64_with_NaT(self):
11721174
def test_min_max_dt64_with_NaT_skipna_false(self, tz_naive_fixture):
11731175
# GH#36907
11741176
tz = tz_naive_fixture
1177+
if isinstance(tz, tzlocal) and is_platform_windows():
1178+
pytest.xfail(
1179+
reason="GH#37659 OSError raised within tzlocal bc Windows "
1180+
"chokes in times before 1970-01-01"
1181+
)
1182+
11751183
df = DataFrame(
11761184
{
11771185
"a": [

pandas/tests/indexes/datetimes/test_ops.py

+23-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from datetime import datetime
22

3+
from dateutil.tz import tzlocal
34
import numpy as np
45
import pytest
56

7+
from pandas.compat import IS64
8+
69
import pandas as pd
710
from pandas import (
811
DateOffset,
@@ -106,24 +109,27 @@ def test_repeat(self, tz_naive_fixture):
106109
with pytest.raises(ValueError, match=msg):
107110
np.repeat(rng, reps, axis=1)
108111

109-
def test_resolution(self, tz_naive_fixture):
112+
@pytest.mark.parametrize(
113+
"freq,expected",
114+
[
115+
("A", "day"),
116+
("Q", "day"),
117+
("M", "day"),
118+
("D", "day"),
119+
("H", "hour"),
120+
("T", "minute"),
121+
("S", "second"),
122+
("L", "millisecond"),
123+
("U", "microsecond"),
124+
],
125+
)
126+
def test_resolution(self, tz_naive_fixture, freq, expected):
110127
tz = tz_naive_fixture
111-
for freq, expected in zip(
112-
["A", "Q", "M", "D", "H", "T", "S", "L", "U"],
113-
[
114-
"day",
115-
"day",
116-
"day",
117-
"day",
118-
"hour",
119-
"minute",
120-
"second",
121-
"millisecond",
122-
"microsecond",
123-
],
124-
):
125-
idx = pd.date_range(start="2013-04-01", periods=30, freq=freq, tz=tz)
126-
assert idx.resolution == expected
128+
if freq == "A" and not IS64 and isinstance(tz, tzlocal):
129+
pytest.xfail(reason="OverflowError inside tzlocal past 2038")
130+
131+
idx = pd.date_range(start="2013-04-01", periods=30, freq=freq, tz=tz)
132+
assert idx.resolution == expected
127133

128134
def test_value_counts_unique(self, tz_naive_fixture):
129135
tz = tz_naive_fixture

pandas/tests/tseries/offsets/test_offsets.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import date, datetime, time as dt_time, timedelta
22
from typing import Dict, List, Optional, Tuple, Type
33

4+
from dateutil.tz import tzlocal
45
import numpy as np
56
import pytest
67

@@ -14,6 +15,7 @@
1415
import pandas._libs.tslibs.offsets as liboffsets
1516
from pandas._libs.tslibs.offsets import ApplyTypeError, _get_offset, _offset_map
1617
from pandas._libs.tslibs.period import INVALID_FREQ_ERR_MSG
18+
from pandas.compat import IS64
1719
from pandas.compat.numpy import np_datetime64_compat
1820
from pandas.errors import PerformanceWarning
1921

@@ -129,6 +131,8 @@ def test_apply_out_of_range(self, tz_naive_fixture):
129131
tz = tz_naive_fixture
130132
if self._offset is None:
131133
return
134+
if isinstance(tz, tzlocal) and not IS64:
135+
pytest.xfail(reason="OverflowError inside tzlocal past 2038")
132136

133137
# try to create an out-of-bounds result timestamp; if we can't create
134138
# the offset skip

0 commit comments

Comments
 (0)