Skip to content

Commit 3c93e41

Browse files
committed
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 python/cpython#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.
1 parent b3fadcb commit 3c93e41

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

lib/matplotlib/axes/_base.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3213,7 +3213,8 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
32133213
reverse = left > right
32143214
left, right = self.xaxis.get_major_locator().nonsingular(left, right)
32153215
left, right = self.xaxis.limit_range_for_scale(left, right)
3216-
left, right = sorted([left, right], reverse=reverse)
3216+
# cast to bool to avoid bad interaction between python 3.8 and np.bool_
3217+
left, right = sorted([left, right], reverse=bool(reverse))
32173218

32183219
self._viewLim.intervalx = (left, right)
32193220
if auto is not None:
@@ -3597,7 +3598,8 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
35973598
reverse = bottom > top
35983599
bottom, top = self.yaxis.get_major_locator().nonsingular(bottom, top)
35993600
bottom, top = self.yaxis.limit_range_for_scale(bottom, top)
3600-
bottom, top = sorted([bottom, top], reverse=reverse)
3601+
# cast to bool to avoid bad interaction between python 3.8 and np.bool_
3602+
bottom, top = sorted([bottom, top], reverse=bool(reverse))
36013603

36023604
self._viewLim.intervaly = (bottom, top)
36033605
if auto is not None:

lib/matplotlib/axis.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,8 @@ def get_minpos(self):
21692169
def set_inverted(self, inverted):
21702170
# docstring inherited
21712171
a, b = self.get_view_interval()
2172-
self.axes.set_xlim(sorted((a, b), reverse=inverted), auto=None)
2172+
# cast to bool to avoid bad interaction between python 3.8 and np.bool_
2173+
self.axes.set_xlim(sorted((a, b), reverse=bool(inverted)), auto=None)
21732174

21742175
def set_default_intervals(self):
21752176
# docstring inherited
@@ -2468,7 +2469,8 @@ def get_minpos(self):
24682469
def set_inverted(self, inverted):
24692470
# docstring inherited
24702471
a, b = self.get_view_interval()
2471-
self.axes.set_ylim(sorted((a, b), reverse=inverted), auto=None)
2472+
# cast to bool to avoid bad interaction between python 3.8 and np.bool_
2473+
self.axes.set_ylim(sorted((a, b), reverse=bool(inverted)), auto=None)
24722474

24732475
def set_default_intervals(self):
24742476
# docstring inherited

lib/mpl_toolkits/mplot3d/axes3d.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False,
619619
reverse = left > right
620620
left, right = self.xaxis.get_major_locator().nonsingular(left, right)
621621
left, right = self.xaxis.limit_range_for_scale(left, right)
622-
left, right = sorted([left, right], reverse=reverse)
622+
# cast to bool to avoid bad interaction between python 3.8 and np.bool_
623+
left, right = sorted([left, right], reverse=bool(reverse))
623624
self.xy_viewLim.intervalx = (left, right)
624625

625626
if auto is not None:

0 commit comments

Comments
 (0)