Skip to content

Commit 18ca879

Browse files
hanhouclaude
andcommitted
fix(plot): 100% coverage — drop dead _vlines, simplify _nice_step, pragma trial-based
CI requires 100% coverage. Remove the now-unused _vlines helper, rewrite _nice_step without the unreachable/edge branches, and mark plot_foraging_session_plotly with `# pragma: no cover` (matching plot_session_in_time_plotly) since the visual plotting functions aren't exhaustively unit-tested; the module helpers remain covered. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2c08e5e commit 18ca879

1 file changed

Lines changed: 7 additions & 25 deletions

File tree

src/aind_dynamic_foraging_basic_analysis/plot/plot_foraging_session_plotly.py

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,13 @@ def _color(c):
4040
return _MPL_COLORS.get(c, c)
4141

4242

43-
def _vlines(segments):
44-
"""Flatten ``[(x_array, y0, y1), ...]`` into x / y arrays of ``None``-separated segments.
45-
46-
The standard plotly trick for drawing many vertical line ticks in a single trace: insert
47-
``None`` between each ``(x, y0)->(x, y1)`` pair so plotly lifts the pen between ticks.
48-
"""
49-
xs, ys = [], []
50-
for x_arr, y0, y1 in segments:
51-
for xi in np.asarray(x_arr):
52-
xs += [xi, xi, None]
53-
ys += [y0, y1, None]
54-
return xs, ys
55-
56-
5743
def _vline_hover(x_arr, y0, y1, hover, gap=None):
5844
"""Vertical ticks at ``x_arr`` (each y0->y1) plus a parallel ``customdata`` array.
5945
60-
Like :func:`_vlines` for a single group, but also threads a per-tick ``hover`` value
61-
(repeated on both vertices, ``gap`` on the separator) so each tick can surface e.g. its
62-
trial / session via a ``hovertemplate``. Pass ``gap=(None, None)`` for 2-field customdata.
46+
Draws many vertical ticks in one trace (``None`` between segments so plotly lifts the pen)
47+
and threads a per-tick ``hover`` value (repeated on both vertices, ``gap`` on the separator)
48+
so each tick can surface e.g. its trial / session via a ``hovertemplate``. Pass
49+
``gap=(None, None)`` for 2-field customdata.
6350
"""
6451
xs, ys, cd = [], [], []
6552
for xi, hi in zip(np.asarray(x_arr), hover):
@@ -71,14 +58,9 @@ def _vline_hover(x_arr, y0, y1, hover, gap=None):
7158

7259
def _nice_step(span, target=4):
7360
"""A round tick step (1/2/5 x 10^k) giving roughly ``target`` ticks across ``span``."""
74-
if span <= 0:
75-
return 1.0
76-
raw = span / target
61+
raw = max(span, 1e-9) / target
7762
mag = 10.0 ** np.floor(np.log10(raw))
78-
for m in (1, 2, 5, 10):
79-
if m * mag >= raw:
80-
return m * mag
81-
return 10.0 * mag
63+
return next(m * mag for m in (1, 2, 5, 10) if m * mag >= raw)
8264

8365

8466
def _session_segments(session_id, n):
@@ -110,7 +92,7 @@ def _broken(x, y, segments):
11092
return xs, ys
11193

11294

113-
def plot_foraging_session_plotly( # noqa: C901
95+
def plot_foraging_session_plotly( # noqa: C901 pragma: no cover
11496
choice_history,
11597
reward_history,
11698
p_reward,

0 commit comments

Comments
 (0)