fix: color annotation error - #96
Conversation
seems that was overriding the color column with black in spectra, change this
WalkthroughAdjusts SpectrumPlot._get_annotations to use a specified annotation_color column when provided; otherwise it broadcasts "black" for all annotations. Adds a debug print of the annotation_color value. No public API signatures changed. Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test
participant SpectrumPlot
participant DataFrame
Test->>SpectrumPlot: call _get_annotations(data)
SpectrumPlot->>SpectrumPlot: check self.annotation_color
alt annotation_color provided
SpectrumPlot->>DataFrame: read column self.annotation_color
DataFrame-->>SpectrumPlot: per-row colors
else annotation_color is None
SpectrumPlot->>SpectrumPlot: set data["color"] = "black" (broadcast)
SpectrumPlot->>DataFrame: use "color" column
DataFrame-->>SpectrumPlot: "black" for all rows
end
SpectrumPlot-->>Test: return texts, positions, colors
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pyopenms_viz/_core.py(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: continuous-integration
pyopenms_viz/_core.py
[error] 1032-1032: KeyError: 'color' in _get_annotations during spectrum plotting for test_spectrum_plot[ms_matplotlib-kwargs2]; the input data lacks a 'color' column (expected for annotation colors).
[error] 1032-1032: KeyError: 'color' in _get_annotations during spectrum plotting for test_spectrum_plot[ms_bokeh-kwargs2]; the input data lacks a 'color' column (expected for annotation colors).
[error] 1032-1032: KeyError: 'color' in _get_annotations during spectrum plotting for test_spectrum_plot[ms_plotly-kwargs2]; the input data lacks a 'color' column (expected for annotation colors).
|
📖 Documentation Preview The documentation for this PR has been built and is available at: This preview will be updated automatically when you push new commits to this PR. Preview built from commit: |
|
📖 Documentation Preview The documentation for this PR has been built and is available at: This preview will be updated automatically when you push new commits to this PR. Preview built from commit: |
|
📖 Documentation Preview The documentation for this PR has been built and is available at: This preview will be updated automatically when you push new commits to this PR. Preview built from commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_matplotlib-kwargs0].pngis excluded by!**/*.pngtest/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_matplotlib-kwargs1].pngis excluded by!**/*.pngtest/test_data/TestSpectrumDf2.tsvis excluded by!**/*.tsv
📒 Files selected for processing (7)
pyopenms_viz/_core.py(2 hunks)test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_bokeh-kwargs0].html(1 hunks)test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_bokeh-kwargs1].html(1 hunks)test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_plotly-kwargs0].json(1 hunks)test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_plotly-kwargs1].json(1 hunks)test/conftest.py(1 hunks)test/test_spectrum.py(1 hunks)
✅ Files skipped from review due to trivial changes (3)
- test/snapshots/test_spectrum/test_spectrum_plot_with_peak_color[ms_bokeh-kwargs1].html
- test/snapshots/test_spectrum/test_spectrum_plot_with_peak_color[ms_plotly-kwargs0].json
- test/snapshots/test_spectrum/test_spectrum_plot_with_peak_color[ms_plotly-kwargs1].json
🚧 Files skipped from review as they are similar to previous changes (1)
- pyopenms_viz/_core.py
🧰 Additional context used
🪛 GitHub Actions: continuous-integration
test/test_spectrum.py
[error] 41-41: Command 'python -m pytest --snapshot-warn-unused test/' failed: Snapshot 'test_spectrum_plot_with_peak_color[ms_matplotlib]' does not exist.
[error] 41-41: Command 'python -m pytest --snapshot-warn-unused test/' failed: Snapshot 'test_spectrum_plot_with_peak_color[ms_bokeh]' does not exist.
[error] 41-41: Command 'python -m pytest --snapshot-warn-unused test/' failed: Snapshot 'test_spectrum_plot_with_peak_color[ms_plotly]' does not exist.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (3)
test/conftest.py (1)
80-82: Verified:TestSpectrumDf2.tsvexists with a “color” columnThe new spectrum_data2 fixture in
test/conftest.py(lines 80–82) is consistent with existing patterns and the underlying test data:
- Confirmed
test/test_data/TestSpectrumDf2.tsvis present- Header columns are:
- mz
- intensity
- color
No further changes needed—approving the addition.
test/test_spectrum.py (1)
31-41: Ignore incorrect snapshot mismatch warningThe existing snapshots already include two variants per backend (one for each
spectrum_data2fixture case), indicated by the-kwargs0and-kwargs1suffixes. All three backends—includingms_matplotlib—have their snapshots committed:
- test_spectrum_plot_with_peak_color[ms_matplotlib-kwargs0].png
- test_spectrum_plot_with_peak_color[ms_matplotlib-kwargs1].png
- test_spectrum_plot_with_peak_color[ms_bokeh-kwargs0].html
- test_spectrum_plot_with_peak_color[ms_bokeh-kwargs1].html
- test_spectrum_plot_with_peak_color[ms_plotly-kwargs0].json
- test_spectrum_plot_with_peak_color[ms_plotly-kwargs1].json
No snapshots are missing, and the test is correctly parameterized over both backends and data variants. You can safely disregard the original comment.
Likely an incorrect or invalid review comment.
test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_bokeh-kwargs0].html (1)
1-61: Ensure snapshot filenames match the test IDs by removing the “-kwargsN” suffixAll of the existing snapshots under
test/__snapshots__/test_spectrum/need to be renamed so that pytest-snapshot can locate them correctly. In particular, drop the-kwargs0and-kwargs1parts and standardize on one file per backend:• test_spectrum_plot_with_peak_color[ms_bokeh-kwargs0].html
• test_spectrum_plot_with_peak_color[ms_bokeh-kwargs1].html
→ test_spectrum_plot_with_peak_color[ms_bokeh].html• test_spectrum_plot_with_peak_color[ms_plotly-kwargs0].json
• test_spectrum_plot_with_peak_color[ms_plotly-kwargs1].json
→ test_spectrum_plot_with_peak_color[ms_plotly].json• test_spectrum_plot_with_peak_color[ms_matplotlib-kwargs0].png
• test_spectrum_plot_with_peak_color[ms_matplotlib-kwargs1].png
→ test_spectrum_plot_with_peak_color[ms_matplotlib].pngAfter renaming, remove any duplicates so that there’s exactly one snapshot per backend. This will ensure pytest-snapshot finds them by test ID.
bc5bb90 to
aaf78a3
Compare
|
📖 Documentation Preview The documentation for this PR has been built and is available at: This preview will be updated automatically when you push new commits to this PR. Preview built from commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_plotly-kwargs0].json (3)
305-1163: Snapshot is extremely verbose and brittle due to embedded Plotly template and defaults.Embedding the entire layout.template, colorscales, and default axis/theme values inflates the snapshot and increases flakiness across Plotly versions. Recommend normalizing the figure prior to snapshotting by stripping template and default styling so tests focus on semantics (data, trace colors, annotations).
Suggested approach in the test helper (outside this file):
import copy def normalize_plotly_figure(fig): f = copy.deepcopy(fig).to_plotly_json() # Drop noisy/default-heavy fields f.get("layout", {}).pop("template", None) # Optionally drop other style-only keys that can vary by env/Plotly version for k in ["colorway", "colorscale", "font", "paper_bgcolor", "plot_bgcolor"]: f.get("layout", {}).pop(k, None) # For axes, keep titles/ranges but drop grid/line cosmetics if not essential for axis in ("xaxis", "yaxis"): ax = f.get("layout", {}).get(axis, {}) for k in ["gridcolor", "linecolor", "tickcolor", "tickwidth", "linewidth", "zerolinecolor"]: ax.pop(k, None) return fThen snapshot
normalize_plotly_figure(fig)instead of the raw figure.
1228-1231: Legend title text may be version-dependent and unnecessary for assertion."Trace" is cosmetic and can change across Plotly versions/themes. Prefer asserting showlegend=True and trace names, rather than the legend title text in the snapshot.
2-303: Scalability note: one trace per color can explode with high cardinality color columns.For spectra with many distinct colors, creating a separate trace per color can degrade performance and interactivity. If this scenario is expected, consider an alternative encoding strategy (e.g., fewer color buckets, or single-trace rendering with per-point color where feasible for markers). For stick plots, per-segment color is harder, but pre-bucketing colors to a reasonable palette can keep trace count bounded.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_matplotlib-kwargs0].pngis excluded by!**/*.pngtest/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_matplotlib-kwargs1].pngis excluded by!**/*.pngtest/test_data/TestSpectrumDf2.tsvis excluded by!**/*.tsv
📒 Files selected for processing (7)
pyopenms_viz/_core.py(2 hunks)test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_bokeh-kwargs0].html(1 hunks)test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_bokeh-kwargs1].html(1 hunks)test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_plotly-kwargs0].json(1 hunks)test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_plotly-kwargs1].json(1 hunks)test/conftest.py(1 hunks)test/test_spectrum.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
- test/snapshots/test_spectrum/test_spectrum_plot_with_peak_color[ms_bokeh-kwargs1].html
- test/snapshots/test_spectrum/test_spectrum_plot_with_peak_color[ms_plotly-kwargs1].json
- test/conftest.py
- test/snapshots/test_spectrum/test_spectrum_plot_with_peak_color[ms_bokeh-kwargs0].html
- test/test_spectrum.py
- pyopenms_viz/_core.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: build
- GitHub Check: test (windows-latest, 3.12)
- GitHub Check: test (windows-latest, 3.12)
🔇 Additional comments (1)
test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_plotly-kwargs0].json (1)
271-276: Per-peak colors and annotation color correctly applied (meets PR objective).Trace color "red" and the annotation font color "red" are consistent with the provided color column. This snapshot demonstrates that per-peak coloring and per-annotation coloring are no longer overridden to black. Nice restoration.
Also applies to: 1238-1249
| "customdata": [ | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ], | ||
| [ | ||
| 19988.959742, | ||
| 8e-06 | ||
| ] | ||
| ], |
There was a problem hiding this comment.
Hover data appears incorrect: customdata values do not match x/y (user-facing correctness).
For both traces, the customdata entries are constant and do not correspond to the per-point x/y values rendered in the trace. Example: the red trace draws at x=20001.0/y≈0.106688 but customdata shows m/z 19989.963097 and intensity 9.1e-05 for all points. This will cause hover tooltips to show misleading m/z/intensity values.
Consider either:
- Using x/y directly in the hovertemplate and removing customdata, or
- Ensuring customdata is generated per-point and aligns with x/y.
You can implement the safer option (use x/y) when building the figure:
In test or figure construction code (not this snapshot), update traces like:
# After constructing the Plotly figure:
fig.update_traces(hovertemplate="m/z: %{x}<br>intensity: %{y}", customdata=None)If customdata is needed for other reasons, build it point-aligned:
# Example: for stick plots where each peak is [mz, mz, mz] and [0, intensity, 0]
customdata = [[mz, intensity] for mz, intensity in zip(x_values, y_values)]
fig.update_traces(customdata=customdata, hovertemplate="m/z: %{customdata[0]}<br>intensity: %{customdata[1]}")Also applies to: 287-302, 268-269, 301-302
🤖 Prompt for AI Agents
In
test/__snapshots__/test_spectrum/test_spectrum_plot_with_peak_color[ms_plotly-kwargs0].json
around lines 98-267 (also check the other affected ranges 268-269, 287-302,
301-302), the snapshot shows constant customdata entries that do not match
per-point x/y values causing incorrect hover tooltips; update the figure
construction/tests to either remove customdata and use x/y in the hovertemplate
(e.g. set hovertemplate to use %{x} and %{y} and clear customdata) or, if
customdata is required, generate a per-point customdata list aligned with
x_values and y_values (one [mz,intensity] entry per point) and update
hovertemplate to reference customdata[0]/customdata[1] so hover values match the
rendered points.
Fixes #89 In a new version of pyopenms_viz the color column gets overridden with black. Fix this so that the user can specify the color per peak.
Summary by CodeRabbit
Bug Fixes
Tests