From f2bb2181d3878259305eabe614c13ccf7a116790 Mon Sep 17 00:00:00 2001 From: gnaggnoyil Date: Sun, 13 Aug 2017 04:44:05 +0800 Subject: [PATCH 1/4] fix leaked exception in RRuleLocator.tick_values --- .gitignore | 1 + lib/matplotlib/dates.py | 2 +- lib/matplotlib/tests/test_dates.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 97dd01c18445..8191bc39e393 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ .pydevproject *.swp .idea +.vscode/ # Compiled source # ################### diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index bd27bef3759a..3edae0c2025e 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -840,7 +840,7 @@ def tick_values(self, vmin, vmax): # We need to cap at the endpoints of valid datetime try: start = vmin - delta - except ValueError: + except (ValueError, OverflowError): start = _from_ordinalf(1.0) try: diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 5a25e6182b7e..7192f615637f 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -128,6 +128,23 @@ def test_RRuleLocator(): fig.autofmt_xdate() +def test_RRuleLocator_dayrange(): + ret = 0 + + try: + loc = mdates.DayLocator() + x1 = datetime.datetime(year=1, month=1, day=1) + y1 = datetime.datetime(year=1, month=1, day=16) + loc.tick_values(x1, y1) + except OverflowError: + # On success, no overflow error shall be thrown + ret = 1 + except: + pass + + assert ret == 0 + + @image_comparison(baseline_images=['DateFormatter_fractionalSeconds'], extensions=['png']) def test_DateFormatter(): From 7f5ff2b827e3f037e3c39294afe0fdfb1e98a91f Mon Sep 17 00:00:00 2001 From: gnaggnoyil Date: Sun, 13 Aug 2017 05:43:26 +0800 Subject: [PATCH 2/4] remove unnecessary try block in test_RRuleLocator_dayrange --- lib/matplotlib/tests/test_dates.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 7192f615637f..58447a7335e3 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -129,20 +129,11 @@ def test_RRuleLocator(): def test_RRuleLocator_dayrange(): - ret = 0 - - try: - loc = mdates.DayLocator() - x1 = datetime.datetime(year=1, month=1, day=1) - y1 = datetime.datetime(year=1, month=1, day=16) - loc.tick_values(x1, y1) - except OverflowError: - # On success, no overflow error shall be thrown - ret = 1 - except: - pass - - assert ret == 0 + loc = mdates.DayLocator() + x1 = datetime.datetime(year=1, month=1, day=1) + y1 = datetime.datetime(year=1, month=1, day=16) + loc.tick_values(x1, y1) + # On success, no overflow error shall be thrown @image_comparison(baseline_images=['DateFormatter_fractionalSeconds'], From 59cb7b09d59debf608f30235e109a5426943207e Mon Sep 17 00:00:00 2001 From: gnaggnoyil Date: Sun, 13 Aug 2017 06:05:41 +0800 Subject: [PATCH 3/4] fix leaked exception in RRuleLocator.tick_values --- lib/matplotlib/dates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index 3edae0c2025e..3dff61acfde8 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -845,7 +845,7 @@ def tick_values(self, vmin, vmax): try: stop = vmax + delta - except ValueError: + except (ValueError, OverflowError): # The magic number! stop = _from_ordinalf(3652059.9999999) From e289d774ff8de9fadbb7e72039b2da6ae56d9eec Mon Sep 17 00:00:00 2001 From: gnaggnoyil Date: Sun, 13 Aug 2017 07:09:42 +0800 Subject: [PATCH 4/4] correct test_RRuleLocator_dayrange --- lib/matplotlib/tests/test_dates.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 58447a7335e3..9f69d2ea7639 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -130,8 +130,8 @@ def test_RRuleLocator(): def test_RRuleLocator_dayrange(): loc = mdates.DayLocator() - x1 = datetime.datetime(year=1, month=1, day=1) - y1 = datetime.datetime(year=1, month=1, day=16) + x1 = datetime.datetime(year=1, month=1, day=1, tzinfo=pytz.UTC) + y1 = datetime.datetime(year=1, month=1, day=16, tzinfo=pytz.UTC) loc.tick_values(x1, y1) # On success, no overflow error shall be thrown