Skip to content

Commit da6cc34

Browse files
committed
Merge pull request matplotlib#2744 from perimosocordiae/patch-1
handle NaN case nicely in _is_sorted
2 parents 762070b + b44c262 commit da6cc34

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/matplotlib/lines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def _is_sorted(self, x):
504504
"""return true if x is sorted"""
505505
if len(x) < 2:
506506
return 1
507-
return np.alltrue(x[1:] - x[0:-1] >= 0)
507+
return np.amin(x[1:] - x[0:-1]) >= 0
508508

509509
@allow_rasterization
510510
def draw(self, renderer):

lib/matplotlib/tests/test_lines.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,11 @@ def test_set_line_coll_dash_image():
7878

7979
np.random.seed(0)
8080
cs = ax.contour(np.random.randn(20, 30), linestyles=[(0, (3, 3))])
81+
82+
83+
def test_nan_is_sorted():
84+
# Exercises issue from PR #2744 (NaN throwing warning in _is_sorted)
85+
line = mpl.lines.Line2D([],[])
86+
assert_true(line._is_sorted(np.array([1,2,3])))
87+
assert_true(not line._is_sorted(np.array([1,np.nan,3])))
88+

0 commit comments

Comments
 (0)