Skip to content

Commit 181dcf1

Browse files
committed
MNT: explicitly cast np.bool_ -> bool to prevent derpcation warnings
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 181dcf1

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,7 +3213,7 @@ 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+
left, right = sorted([left, right], reverse=bool(reverse))
32173217

32183218
self._viewLim.intervalx = (left, right)
32193219
if auto is not None:
@@ -3597,7 +3597,7 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
35973597
reverse = bottom > top
35983598
bottom, top = self.yaxis.get_major_locator().nonsingular(bottom, top)
35993599
bottom, top = self.yaxis.limit_range_for_scale(bottom, top)
3600-
bottom, top = sorted([bottom, top], reverse=reverse)
3600+
bottom, top = sorted([bottom, top], reverse=bool(reverse))
36013601

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

lib/matplotlib/axis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ 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+
self.axes.set_xlim(sorted((a, b), reverse=bool(inverted)), auto=None)
21732173

21742174
def set_default_intervals(self):
21752175
# docstring inherited
@@ -2468,7 +2468,7 @@ def get_minpos(self):
24682468
def set_inverted(self, inverted):
24692469
# docstring inherited
24702470
a, b = self.get_view_interval()
2471-
self.axes.set_ylim(sorted((a, b), reverse=inverted), auto=None)
2471+
self.axes.set_ylim(sorted((a, b), reverse=bool(inverted)), auto=None)
24722472

24732473
def set_default_intervals(self):
24742474
# docstring inherited

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ 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+
left, right = sorted([left, right], reverse=bool(reverse))
623623
self.xy_viewLim.intervalx = (left, right)
624624

625625
if auto is not None:

0 commit comments

Comments
 (0)