From d03c676238e0205f5cc1e0e3574b06f499e31fb6 Mon Sep 17 00:00:00 2001 From: kjain Date: Sat, 26 Mar 2022 18:40:14 +0100 Subject: [PATCH 01/13] Update axis.py --- lib/matplotlib/axis.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index e80e49e53bb9..3b243c79f6f1 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1825,8 +1825,10 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs): For each tick, includes ``tick.label1`` if it is visible, then ``tick.label2`` if it is visible, in that order. """ - ticklabels = [t.get_text() if hasattr(t, 'get_text') else t - for t in ticklabels] + ticklabels = [] + for t in ticklabels: + if hasattr(t, 'get_text'): + ticklabels.append(t.get_text()) locator = (self.get_minor_locator() if minor else self.get_major_locator()) if isinstance(locator, mticker.FixedLocator): From 2ad730cb4d2abd98c127baf7d8e942af937b9b11 Mon Sep 17 00:00:00 2001 From: kjain Date: Sat, 26 Mar 2022 18:53:51 +0100 Subject: [PATCH 02/13] Update axis.py --- lib/matplotlib/axis.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 3b243c79f6f1..b5bf01765495 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1826,9 +1826,9 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs): ``tick.label2`` if it is visible, in that order. """ ticklabels = [] - for t in ticklabels: - if hasattr(t, 'get_text'): - ticklabels.append(t.get_text()) + for t in ticklabels: + if hasattr(t, 'get_text'): + ticklabels.append(t.get_text()) locator = (self.get_minor_locator() if minor else self.get_major_locator()) if isinstance(locator, mticker.FixedLocator): From 1d225675eba4d78d0780fd137db3ba6db63e358f Mon Sep 17 00:00:00 2001 From: kjain Date: Mon, 28 Mar 2022 23:33:02 +0200 Subject: [PATCH 03/13] Update axis.py --- lib/matplotlib/axis.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index b5bf01765495..7c1718f35e83 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1825,10 +1825,16 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs): For each tick, includes ``tick.label1`` if it is visible, then ``tick.label2`` if it is visible, in that order. """ + + ticklabels = [] - for t in ticklabels: - if hasattr(t, 'get_text'): - ticklabels.append(t.get_text()) + try: + ticklabels = [t.get_text() if hasattr(t, 'get_text') else t + for t in ticklabels] + except: + raise TypeError(f"{ticklabels:=} must be a sequence") from None + + locator = (self.get_minor_locator() if minor else self.get_major_locator()) if isinstance(locator, mticker.FixedLocator): From e7b43a0ca4f2990f1207408a19348c4352ae5d72 Mon Sep 17 00:00:00 2001 From: kjain Date: Tue, 29 Mar 2022 19:42:37 +0200 Subject: [PATCH 04/13] Update axis.py --- lib/matplotlib/axis.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 7c1718f35e83..7a661e623e11 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1825,15 +1825,12 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs): For each tick, includes ``tick.label1`` if it is visible, then ``tick.label2`` if it is visible, in that order. """ - - ticklabels = [] try: - ticklabels = [t.get_text() if hasattr(t, 'get_text') else t + ticklabels = [t.get_text() if hasattr(t, 'get_text') else t for t in ticklabels] - except: - raise TypeError(f"{ticklabels:=} must be a sequence") from None - + except TypeError: + raise TypeError(f"{ticklabels:=} must be a sequence") from None locator = (self.get_minor_locator() if minor else self.get_major_locator()) From 48322da4576bd007fdd3ec367cf65f112787eee7 Mon Sep 17 00:00:00 2001 From: Krish-sysadmin Date: Wed, 30 Mar 2022 22:40:33 +0200 Subject: [PATCH 05/13] add tests --- lib/matplotlib/tests/test_axes.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index a5f5ddad93c4..c87780f7ed3f 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -442,6 +442,8 @@ def test_inverted_cla(): assert not ax.xaxis_inverted() assert ax.yaxis_inverted() + for ax in fig.axes: + ax.remove() # 5. two shared axes. Inverting the leader axis should invert the shared # axes; clearing the leader axis should bring axes in shared # axes back to normal. @@ -5388,6 +5390,12 @@ def test_set_ticks_with_labels(fig_test, fig_ref): ax.set_yticks([2, 4], ['A', 'B'], minor=True) +def test_iterable_ticklabels(): + with pytest.raises(TypeError): + fig, ax = plt.subplots(2) + ax[1].set_xticks([2, 9], 3.1) + + def test_subsampled_ticklabels(): # test issue 11937 fig, ax = plt.subplots() @@ -7604,4 +7612,4 @@ def test_bezier_autoscale(): ax.autoscale() # Bottom ylim should be at the edge of the curve (-0.5), and not include # the control point (at -1) - assert ax.get_ylim()[0] == -0.5 + assert ax.get_ylim()[0] == -0.5 \ No newline at end of file From fab0c5c1e781e93089eba3e23a759e40cad24967 Mon Sep 17 00:00:00 2001 From: Krish-sysadmin Date: Thu, 31 Mar 2022 19:38:43 +0200 Subject: [PATCH 06/13] added fixes --- lib/matplotlib/axis.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 7a661e623e11..566366d8cd0e 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1825,13 +1825,10 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs): For each tick, includes ``tick.label1`` if it is visible, then ``tick.label2`` if it is visible, in that order. """ - ticklabels = [] try: - ticklabels = [t.get_text() if hasattr(t, 'get_text') else t - for t in ticklabels] + ticklabels = [t.get_text() if hasattr(t, 'get_text') else t for t in ticklabels] except TypeError: raise TypeError(f"{ticklabels:=} must be a sequence") from None - locator = (self.get_minor_locator() if minor else self.get_major_locator()) if isinstance(locator, mticker.FixedLocator): From 7240fddc0f251a1ffe35da79c3b5e88cd6e51059 Mon Sep 17 00:00:00 2001 From: Krish-sysadmin Date: Thu, 31 Mar 2022 19:51:30 +0200 Subject: [PATCH 07/13] fixed tests --- lib/matplotlib/tests/test_axes.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index c87780f7ed3f..4f26d566a17d 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -442,8 +442,6 @@ def test_inverted_cla(): assert not ax.xaxis_inverted() assert ax.yaxis_inverted() - for ax in fig.axes: - ax.remove() # 5. two shared axes. Inverting the leader axis should invert the shared # axes; clearing the leader axis should bring axes in shared # axes back to normal. @@ -5390,8 +5388,9 @@ def test_set_ticks_with_labels(fig_test, fig_ref): ax.set_yticks([2, 4], ['A', 'B'], minor=True) -def test_iterable_ticklabels(): - with pytest.raises(TypeError): +def test_set_noniterable_ticklabels(): + # Ensure a useful TypeError message is raised when given a non-iterable ticklabels argument. Pull request #22710 + with pytest.raises(TypeError, match='must be a sequence'): fig, ax = plt.subplots(2) ax[1].set_xticks([2, 9], 3.1) From 4872bbb892cb6d6cd1e84ca73c2838308ff4fc70 Mon Sep 17 00:00:00 2001 From: Krish-sysadmin Date: Thu, 31 Mar 2022 22:36:03 +0200 Subject: [PATCH 08/13] fix lint --- lib/matplotlib/axis.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 566366d8cd0e..e719ba2af862 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1826,7 +1826,8 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs): ``tick.label2`` if it is visible, in that order. """ try: - ticklabels = [t.get_text() if hasattr(t, 'get_text') else t for t in ticklabels] + ticklabels = [t.get_text() if hasattr(t, 'get_text') else t + for t in ticklabels] except TypeError: raise TypeError(f"{ticklabels:=} must be a sequence") from None locator = (self.get_minor_locator() if minor From ee15d9ba503741f77ab2dc97738e993bbebf2e89 Mon Sep 17 00:00:00 2001 From: Krish-sysadmin Date: Thu, 31 Mar 2022 22:42:04 +0200 Subject: [PATCH 09/13] linting --- lib/matplotlib/tests/test_axes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 4f26d566a17d..37932d9c2838 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5389,7 +5389,9 @@ def test_set_ticks_with_labels(fig_test, fig_ref): def test_set_noniterable_ticklabels(): - # Ensure a useful TypeError message is raised when given a non-iterable ticklabels argument. Pull request #22710 + # Ensure a useful TypeError message is raised + # when given a non-iterable ticklabels argument + # Pull request #22710 with pytest.raises(TypeError, match='must be a sequence'): fig, ax = plt.subplots(2) ax[1].set_xticks([2, 9], 3.1) From d8162f01e62a4b9450070f36a7c92dc818ebce44 Mon Sep 17 00:00:00 2001 From: kjain Date: Sat, 2 Apr 2022 21:18:14 +0200 Subject: [PATCH 10/13] Update test_axes.py --- lib/matplotlib/tests/test_axes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 37932d9c2838..c7dc7386f7f7 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -7613,4 +7613,5 @@ def test_bezier_autoscale(): ax.autoscale() # Bottom ylim should be at the edge of the curve (-0.5), and not include # the control point (at -1) - assert ax.get_ylim()[0] == -0.5 \ No newline at end of file + assert ax.get_ylim()[0] == -0.5 + From 95c42de9410d1555f2500a7262d310ddbcdb0353 Mon Sep 17 00:00:00 2001 From: Krish-sysadmin Date: Sun, 3 Apr 2022 16:38:02 +0200 Subject: [PATCH 11/13] visual indentation --- lib/matplotlib/axis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index e719ba2af862..eb0c00801d7b 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1827,7 +1827,7 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs): """ try: ticklabels = [t.get_text() if hasattr(t, 'get_text') else t - for t in ticklabels] + for t in ticklabels] except TypeError: raise TypeError(f"{ticklabels:=} must be a sequence") from None locator = (self.get_minor_locator() if minor From 61661cdcedc3f5e7c63b75571afb5b944946af80 Mon Sep 17 00:00:00 2001 From: Krish-sysadmin Date: Mon, 4 Apr 2022 22:05:27 +0200 Subject: [PATCH 12/13] removed whitespace --- lib/matplotlib/tests/test_axes.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index c7dc7386f7f7..23e8388844d2 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -7613,5 +7613,4 @@ def test_bezier_autoscale(): ax.autoscale() # Bottom ylim should be at the edge of the curve (-0.5), and not include # the control point (at -1) - assert ax.get_ylim()[0] == -0.5 - + assert ax.get_ylim()[0] == -0.5 From 7f9048d6814ca5e2e23b275110f05020f79201f1 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 4 Apr 2022 19:58:50 -0400 Subject: [PATCH 13/13] STY: remove trailing whitespace --- lib/matplotlib/tests/test_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 23e8388844d2..59ce45b107d4 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -7613,4 +7613,4 @@ def test_bezier_autoscale(): ax.autoscale() # Bottom ylim should be at the edge of the curve (-0.5), and not include # the control point (at -1) - assert ax.get_ylim()[0] == -0.5 + assert ax.get_ylim()[0] == -0.5