From 35353f93c3d6d96c9ca9f3176c82a0a668d6d09c Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Thu, 9 Nov 2017 16:27:19 -0800 Subject: [PATCH 1/3] Catch SystemError in py3 Period.__richcmp__ --- pandas/_libs/period.pyx | 7 ++++++- pandas/tests/scalar/test_period.py | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/period.pyx b/pandas/_libs/period.pyx index 72523a19b9595..5c5c10684551d 100644 --- a/pandas/_libs/period.pyx +++ b/pandas/_libs/period.pyx @@ -693,7 +693,12 @@ cdef class _Period(object): def __richcmp__(self, other, op): if is_period_object(other): - if other.freq != self.freq: + try: + if other.freq != self.freq: + msg = _DIFFERENT_FREQ.format(self.freqstr, other.freqstr) + raise IncompatibleFrequency(msg) + except SystemError: + # See GH#17112 in python3 msg = _DIFFERENT_FREQ.format(self.freqstr, other.freqstr) raise IncompatibleFrequency(msg) return PyObject_RichCompareBool(self.ordinal, other.ordinal, op) diff --git a/pandas/tests/scalar/test_period.py b/pandas/tests/scalar/test_period.py index 28d85c52604d9..a99c06b18dafc 100644 --- a/pandas/tests/scalar/test_period.py +++ b/pandas/tests/scalar/test_period.py @@ -1418,3 +1418,11 @@ def test_period_immutable(): freq = per.freq with pytest.raises(AttributeError): per.freq = 2 * freq + +def test_comparison_catches_system_error(): + # see GH#17112 in py3 this comparison could raise SystemError instead + # of IncompatibleFrequency + per1 = pd.Period('2014Q1') + per2 = pd.Period('2015', freq='A') + with pytest.raises(IncompatibleFrequency): + per1 < per2 From 9f4945195d6cd3a15b77a98f5bc97c580bbce2fc Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Thu, 9 Nov 2017 16:29:53 -0800 Subject: [PATCH 2/3] full name --- pandas/tests/scalar/test_period.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/scalar/test_period.py b/pandas/tests/scalar/test_period.py index a99c06b18dafc..9ecb92916c643 100644 --- a/pandas/tests/scalar/test_period.py +++ b/pandas/tests/scalar/test_period.py @@ -1424,5 +1424,5 @@ def test_comparison_catches_system_error(): # of IncompatibleFrequency per1 = pd.Period('2014Q1') per2 = pd.Period('2015', freq='A') - with pytest.raises(IncompatibleFrequency): + with pytest.raises(period.IncompatibleFrequency): per1 < per2 From 6b86d59467719d783d8271bbd846b015b56e939a Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Thu, 9 Nov 2017 16:30:24 -0800 Subject: [PATCH 3/3] whitespace fixup --- pandas/tests/scalar/test_period.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/scalar/test_period.py b/pandas/tests/scalar/test_period.py index 9ecb92916c643..2824d2aa266ff 100644 --- a/pandas/tests/scalar/test_period.py +++ b/pandas/tests/scalar/test_period.py @@ -1419,6 +1419,7 @@ def test_period_immutable(): with pytest.raises(AttributeError): per.freq = 2 * freq + def test_comparison_catches_system_error(): # see GH#17112 in py3 this comparison could raise SystemError instead # of IncompatibleFrequency