Skip to content

Commit e216e59

Browse files
brunobeltranQuLogic
authored andcommitted
TESTS: ensure removing nan's doesn't break bar
1 parent 11d00b5 commit e216e59

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

lib/matplotlib/tests/test_axes.py

+5
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,11 @@ def test_bar_tick_label_single():
14041404
ax.bar("a", "b", align='edge', tick_label='0', data=data)
14051405

14061406

1407+
def test_nan_bar_values():
1408+
fig, ax = plt.subplots()
1409+
ax.bar([0, 1], [np.nan, 4])
1410+
1411+
14071412
def test_bar_ticklabel_fail():
14081413
fig, ax = plt.subplots()
14091414
ax.bar([], [])

lib/matplotlib/tests/test_path.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,19 @@ def test_cleanup_closepoly():
459459
# component contains a NaN, then Path.cleaned should ignore not just the
460460
# control points but also the CLOSEPOLY, since it has nowhere valid to
461461
# point.
462-
p = Path([[np.nan, np.nan], [np.nan, np.nan]],
463-
[Path.MOVETO, Path.CLOSEPOLY])
464-
cleaned = p.cleaned(remove_nans=True)
465-
assert len(cleaned) == 1
466-
assert cleaned.codes[0] == Path.STOP
462+
paths = [
463+
Path([[np.nan, np.nan], [np.nan, np.nan]],
464+
[Path.MOVETO, Path.CLOSEPOLY]),
465+
# we trigger a different path in the C++ code if we don't pass any
466+
# codes explicitly, so we must also make sure that this works
467+
Path([[np.nan, np.nan], [np.nan, np.nan]]),
468+
# we should also make sure that this cleanup works if there's some
469+
# multi-vertex curves
470+
Path([[np.nan, np.nan], [np.nan, np.nan], [np.nan, np.nan],
471+
[np.nan, np.nan]],
472+
[Path.MOVETO, Path.CURVE3, Path.CURVE3, Path.CLOSEPOLY])
473+
]
474+
for p in paths:
475+
cleaned = p.cleaned(remove_nans=True)
476+
assert len(cleaned) == 1
477+
assert cleaned.codes[0] == Path.STOP

src/path_converters.h

+12-8
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,13 @@ class PathNanRemover : protected EmbeddedQueue<4>
205205
are found along the way, the queue is emptied, and
206206
the next curve segment is handled. */
207207
code = m_source->vertex(x, y);
208-
if (code == agg::path_cmd_stop) {
209-
return code;
210-
}
211-
if (code == (agg::path_cmd_end_poly | agg::path_flags_close)
212-
&& valid_segment_exists) {
208+
/* The vertices attached to STOP and CLOSEPOLY left are never
209+
used, so we leave them as-is even if NaN. However, CLOSEPOLY
210+
only makes sense if a valid MOVETO command has already been
211+
emitted. */
212+
if (code == agg::path_cmd_stop ||
213+
(code == (agg::path_cmd_end_poly | agg::path_flags_close) &&
214+
valid_segment_exists)) {
213215
return code;
214216
}
215217

@@ -258,21 +260,23 @@ class PathNanRemover : protected EmbeddedQueue<4>
258260
code = m_source->vertex(x, y);
259261

260262
if (code == agg::path_cmd_stop ||
261-
code == (agg::path_cmd_end_poly | agg::path_flags_close)) {
263+
(code == (agg::path_cmd_end_poly | agg::path_flags_close) &&
264+
valid_segment_exists)) {
262265
return code;
263266
}
264267

265268
if (!(std::isfinite(*x) && std::isfinite(*y))) {
266269
do {
267270
code = m_source->vertex(x, y);
268271
if (code == agg::path_cmd_stop ||
269-
code == (agg::path_cmd_end_poly | agg::path_flags_close)) {
272+
(code == (agg::path_cmd_end_poly | agg::path_flags_close) &&
273+
valid_segment_exists)) {
270274
return code;
271275
}
272276
} while (!(std::isfinite(*x) && std::isfinite(*y)));
273277
return agg::path_cmd_move_to;
274278
}
275-
279+
valid_segment_exists = true;
276280
return code;
277281
}
278282
}

0 commit comments

Comments
 (0)