From 38162a3ea4a6087cad74f0c365873062f9c34615 Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Mon, 4 Jan 2021 18:36:15 -0500 Subject: [PATCH 1/6] TST: strict xfail --- pandas/conftest.py | 2 +- pandas/tests/indexing/test_coercion.py | 2 -- pandas/tests/tseries/offsets/common.py | 6 ++++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 2862f7c957abc..bf5e632374b59 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -473,7 +473,7 @@ def index_with_missing(request): Fixture for indices with missing values """ if request.param in ["int", "uint", "range", "empty", "repeats"]: - pytest.xfail("missing values not supported") + pytest.skip("missing values not supported") # GH 35538. Use deep copy to avoid illusive bug on np-dev # Azure pipeline that writes into indices_dict despite copy ind = indices_dict[request.param].copy(deep=True) diff --git a/pandas/tests/indexing/test_coercion.py b/pandas/tests/indexing/test_coercion.py index 8735e2a09920d..68ed4c7b1d83d 100644 --- a/pandas/tests/indexing/test_coercion.py +++ b/pandas/tests/indexing/test_coercion.py @@ -466,8 +466,6 @@ def test_insert_index_datetimes(self, fill_val, exp_dtype): with pytest.raises(TypeError, match=msg): obj.insert(1, 1) - pytest.xfail("ToDo: must coerce to object") - def test_insert_index_timedelta64(self): obj = pd.TimedeltaIndex(["1 day", "2 day", "3 day", "4 day"]) assert obj.dtype == "timedelta64[ns]" diff --git a/pandas/tests/tseries/offsets/common.py b/pandas/tests/tseries/offsets/common.py index b2ac28e1865d6..fe3c89d85eb9b 100644 --- a/pandas/tests/tseries/offsets/common.py +++ b/pandas/tests/tseries/offsets/common.py @@ -98,12 +98,14 @@ def _get_offset(self, klass, value=1, normalize=False): klass = klass(value, normalize=normalize) return klass - def test_apply_out_of_range(self, tz_naive_fixture): + def test_apply_out_of_range(self, request, tz_naive_fixture): tz = tz_naive_fixture if self._offset is None: return if isinstance(tz, tzlocal) and not IS64: - pytest.xfail(reason="OverflowError inside tzlocal past 2038") + request.node.add_marker( + pytest.mark.xfail(reason="OverflowError inside tzlocal past 2038") + ) # try to create an out-of-bounds result timestamp; if we can't create # the offset skip From fa4b3e4edd1f0184245ab9dfb0b7d35d1f6a5586 Mon Sep 17 00:00:00 2001 From: rhshadrach Date: Mon, 4 Jan 2021 20:52:28 -0500 Subject: [PATCH 2/6] Remove OutOfBoundsDatetime except --- pandas/tests/tseries/offsets/common.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/tests/tseries/offsets/common.py b/pandas/tests/tseries/offsets/common.py index fe3c89d85eb9b..99880f5c61345 100644 --- a/pandas/tests/tseries/offsets/common.py +++ b/pandas/tests/tseries/offsets/common.py @@ -127,8 +127,6 @@ def test_apply_out_of_range(self, request, tz_naive_fixture): assert isinstance(result, datetime) assert t.tzinfo == result.tzinfo - except OutOfBoundsDatetime: - pass except (ValueError, KeyError): # we are creating an invalid offset # so ignore From 357c1ba7e90e062ce7041c26802e8186be9dd893 Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Tue, 5 Jan 2021 17:44:14 -0500 Subject: [PATCH 3/6] xfail instead of raises --- pandas/tests/indexing/test_coercion.py | 33 ++++++++++++-------------- pandas/tests/tseries/offsets/common.py | 11 +++++---- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pandas/tests/indexing/test_coercion.py b/pandas/tests/indexing/test_coercion.py index 68ed4c7b1d83d..ac2e300f9f8d6 100644 --- a/pandas/tests/indexing/test_coercion.py +++ b/pandas/tests/indexing/test_coercion.py @@ -436,7 +436,20 @@ def test_insert_index_float64(self, insert, coerced_val, coerced_dtype): ], ids=["datetime64", "datetime64tz"], ) - def test_insert_index_datetimes(self, fill_val, exp_dtype): + @pytest.mark.parametrize( + "insert_value", + [pd.Timestamp("2012-01-01"), pd.Timestamp("2012-01-01", tz="Asia/Tokyo"), 1], + ) + def test_insert_index_datetimes(self, request, fill_val, exp_dtype, insert_value): + if not hasattr(insert_value, "tz"): + request.node.add_marker( + pytest.mark.xfail(reason="ToDo: must coerce to object") + ) + elif fill_val.tz != insert_value.tz: + request.node.add_marker( + pytest.mark.xfail(reason="GH 37605 - require tz equality?") + ) + obj = pd.DatetimeIndex( ["2011-01-01", "2011-01-02", "2011-01-03", "2011-01-04"], tz=fill_val.tz ) @@ -448,23 +461,7 @@ def test_insert_index_datetimes(self, fill_val, exp_dtype): ) self._assert_insert_conversion(obj, fill_val, exp, exp_dtype) - if fill_val.tz: - msg = "Cannot compare tz-naive and tz-aware" - with pytest.raises(TypeError, match=msg): - obj.insert(1, pd.Timestamp("2012-01-01")) - - msg = "Timezones don't match" - with pytest.raises(ValueError, match=msg): - obj.insert(1, pd.Timestamp("2012-01-01", tz="Asia/Tokyo")) - - else: - msg = "Cannot compare tz-naive and tz-aware" - with pytest.raises(TypeError, match=msg): - obj.insert(1, pd.Timestamp("2012-01-01", tz="Asia/Tokyo")) - - msg = "value should be a 'Timestamp' or 'NaT'. Got 'int' instead." - with pytest.raises(TypeError, match=msg): - obj.insert(1, 1) + obj.insert(1, insert_value) def test_insert_index_timedelta64(self): obj = pd.TimedeltaIndex(["1 day", "2 day", "3 day", "4 day"]) diff --git a/pandas/tests/tseries/offsets/common.py b/pandas/tests/tseries/offsets/common.py index 99880f5c61345..90efe3c51832d 100644 --- a/pandas/tests/tseries/offsets/common.py +++ b/pandas/tests/tseries/offsets/common.py @@ -98,14 +98,15 @@ def _get_offset(self, klass, value=1, normalize=False): klass = klass(value, normalize=normalize) return klass - def test_apply_out_of_range(self, request, tz_naive_fixture): + def test_apply_out_of_range(self, tz_naive_fixture): tz = tz_naive_fixture if self._offset is None: return if isinstance(tz, tzlocal) and not IS64: - request.node.add_marker( - pytest.mark.xfail(reason="OverflowError inside tzlocal past 2038") - ) + # request.node.add_marker( + # pytest.mark.xfail(reason="OverflowError inside tzlocal past 2038") + # ) + pass # try to create an out-of-bounds result timestamp; if we can't create # the offset skip @@ -127,6 +128,8 @@ def test_apply_out_of_range(self, request, tz_naive_fixture): assert isinstance(result, datetime) assert t.tzinfo == result.tzinfo + except OutOfBoundsDatetime: + pass except (ValueError, KeyError): # we are creating an invalid offset # so ignore From 17f18bf40af345037c1d0c7132f131e6c0875f0c Mon Sep 17 00:00:00 2001 From: rhshadrach Date: Tue, 5 Jan 2021 21:14:50 -0500 Subject: [PATCH 4/6] Trying larger offset for BusinessDay --- pandas/tests/tseries/offsets/common.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pandas/tests/tseries/offsets/common.py b/pandas/tests/tseries/offsets/common.py index 90efe3c51832d..2a8ccea21ca8f 100644 --- a/pandas/tests/tseries/offsets/common.py +++ b/pandas/tests/tseries/offsets/common.py @@ -98,15 +98,14 @@ def _get_offset(self, klass, value=1, normalize=False): klass = klass(value, normalize=normalize) return klass - def test_apply_out_of_range(self, tz_naive_fixture): + def test_apply_out_of_range(self, request, tz_naive_fixture): tz = tz_naive_fixture if self._offset is None: return if isinstance(tz, tzlocal) and not IS64: - # request.node.add_marker( - # pytest.mark.xfail(reason="OverflowError inside tzlocal past 2038") - # ) - pass + request.node.add_marker( + pytest.mark.xfail(reason="OverflowError inside tzlocal past 2038") + ) # try to create an out-of-bounds result timestamp; if we can't create # the offset skip @@ -116,7 +115,7 @@ def test_apply_out_of_range(self, tz_naive_fixture): # difference offset = self._get_offset(self._offset, value=100000) else: - offset = self._get_offset(self._offset, value=10000) + offset = self._get_offset(self._offset, value=100000) result = Timestamp("20080101") + offset assert isinstance(result, datetime) From 3daf384c6b518d264220db27eae3b3155e4d3d98 Mon Sep 17 00:00:00 2001 From: rhshadrach Date: Tue, 5 Jan 2021 21:23:59 -0500 Subject: [PATCH 5/6] Move xfail down --- pandas/tests/tseries/offsets/common.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pandas/tests/tseries/offsets/common.py b/pandas/tests/tseries/offsets/common.py index 2a8ccea21ca8f..f1f218e980199 100644 --- a/pandas/tests/tseries/offsets/common.py +++ b/pandas/tests/tseries/offsets/common.py @@ -102,10 +102,6 @@ def test_apply_out_of_range(self, request, tz_naive_fixture): tz = tz_naive_fixture if self._offset is None: return - if isinstance(tz, tzlocal) and not IS64: - request.node.add_marker( - pytest.mark.xfail(reason="OverflowError inside tzlocal past 2038") - ) # try to create an out-of-bounds result timestamp; if we can't create # the offset skip @@ -115,7 +111,7 @@ def test_apply_out_of_range(self, request, tz_naive_fixture): # difference offset = self._get_offset(self._offset, value=100000) else: - offset = self._get_offset(self._offset, value=100000) + offset = self._get_offset(self._offset, value=10000) result = Timestamp("20080101") + offset assert isinstance(result, datetime) @@ -125,11 +121,19 @@ def test_apply_out_of_range(self, request, tz_naive_fixture): t = Timestamp("20080101", tz=tz) result = t + offset assert isinstance(result, datetime) + + if isinstance(tz, tzlocal) and not IS64: + # If we hit OutOfBoundsDatetime on non-64 bit machines + # we'll drop out of the try clause before the next test + request.node.add_marker( + pytest.mark.xfail(reason="OverflowError inside tzlocal past 2038") + ) assert t.tzinfo == result.tzinfo except OutOfBoundsDatetime: pass except (ValueError, KeyError): + print("vk") # we are creating an invalid offset # so ignore pass From 822d2c492319136cf08a7f9c3265c994294980c9 Mon Sep 17 00:00:00 2001 From: rhshadrach Date: Tue, 5 Jan 2021 21:30:06 -0500 Subject: [PATCH 6/6] Fixup --- pandas/tests/tseries/offsets/common.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/tseries/offsets/common.py b/pandas/tests/tseries/offsets/common.py index f1f218e980199..5edef896be537 100644 --- a/pandas/tests/tseries/offsets/common.py +++ b/pandas/tests/tseries/offsets/common.py @@ -133,7 +133,6 @@ def test_apply_out_of_range(self, request, tz_naive_fixture): except OutOfBoundsDatetime: pass except (ValueError, KeyError): - print("vk") # we are creating an invalid offset # so ignore pass