From 3c93e410edb53159fc8f3209da1c43d4c792bb15 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 1 Sep 2019 13:06:11 -0400 Subject: [PATCH] MNT: explicitly cast np.bool_ -> bool to prevent deprecation warning This is a workaround to https://bugs.python.org/issue37980 - np.bool raises a warning if you try to use it as an index (by warning in its `__index__` method - in py38 https://github.com/python/cpython/pull/11952 python changes the code path used to convert `np.bool_` -> int for as it is used in `sorted` so it now goes through the `__index__` code path - this causes a bunch of spurious warnings to come out of Matplotlib. --- lib/matplotlib/axes/_base.py | 6 ++++-- lib/matplotlib/axis.py | 6 ++++-- lib/mpl_toolkits/mplot3d/axes3d.py | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 9e36ee9ae9eb..c979fe292d08 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3213,7 +3213,8 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, reverse = left > right left, right = self.xaxis.get_major_locator().nonsingular(left, right) left, right = self.xaxis.limit_range_for_scale(left, right) - left, right = sorted([left, right], reverse=reverse) + # cast to bool to avoid bad interaction between python 3.8 and np.bool_ + left, right = sorted([left, right], reverse=bool(reverse)) self._viewLim.intervalx = (left, right) if auto is not None: @@ -3597,7 +3598,8 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, reverse = bottom > top bottom, top = self.yaxis.get_major_locator().nonsingular(bottom, top) bottom, top = self.yaxis.limit_range_for_scale(bottom, top) - bottom, top = sorted([bottom, top], reverse=reverse) + # cast to bool to avoid bad interaction between python 3.8 and np.bool_ + bottom, top = sorted([bottom, top], reverse=bool(reverse)) self._viewLim.intervaly = (bottom, top) if auto is not None: diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index bff481464d59..2101d802264c 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -2169,7 +2169,8 @@ def get_minpos(self): def set_inverted(self, inverted): # docstring inherited a, b = self.get_view_interval() - self.axes.set_xlim(sorted((a, b), reverse=inverted), auto=None) + # cast to bool to avoid bad interaction between python 3.8 and np.bool_ + self.axes.set_xlim(sorted((a, b), reverse=bool(inverted)), auto=None) def set_default_intervals(self): # docstring inherited @@ -2468,7 +2469,8 @@ def get_minpos(self): def set_inverted(self, inverted): # docstring inherited a, b = self.get_view_interval() - self.axes.set_ylim(sorted((a, b), reverse=inverted), auto=None) + # cast to bool to avoid bad interaction between python 3.8 and np.bool_ + self.axes.set_ylim(sorted((a, b), reverse=bool(inverted)), auto=None) def set_default_intervals(self): # docstring inherited diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index d1be77a553ff..88b4beee70f0 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -619,7 +619,8 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False, reverse = left > right left, right = self.xaxis.get_major_locator().nonsingular(left, right) left, right = self.xaxis.limit_range_for_scale(left, right) - left, right = sorted([left, right], reverse=reverse) + # cast to bool to avoid bad interaction between python 3.8 and np.bool_ + left, right = sorted([left, right], reverse=bool(reverse)) self.xy_viewLim.intervalx = (left, right) if auto is not None: