Skip to content

fix: support datetime values in mo.ui.matplotlib selection masks#8940

Merged
mscolnick merged 2 commits intomainfrom
ms/mpl-numbers
Mar 31, 2026
Merged

fix: support datetime values in mo.ui.matplotlib selection masks#8940
mscolnick merged 2 commits intomainfrom
ms/mpl-numbers

Conversation

@mscolnick
Copy link
Copy Markdown
Contributor

Closes #8936

BoxSelection.get_mask() and LassoSelection.get_mask() raised TypeError when users passed datetime objects as x/y coordinates. The selection bounds from the frontend are matplotlib's internal float representation of dates, but comparing datetime >= float fails.

Added a _to_numeric() helper that detects datetime arrays (datetime.datetime, datetime.date, numpy.datetime64) and converts them to matplotlib's float representation via date2num() before comparison.

Closes #8936

`BoxSelection.get_mask()` and `LassoSelection.get_mask()` raised `TypeError` when users passed `datetime` objects as x/y coordinates. The selection bounds from the frontend are matplotlib's internal float representation of dates, but comparing `datetime >= float` fails.

Added a `_to_numeric()` helper that detects datetime arrays (`datetime.datetime`, `datetime.date`, `numpy.datetime64`) and converts them to matplotlib's float representation via `date2num()` before comparison.
Copilot AI review requested due to automatic review settings March 31, 2026 14:48
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Mar 31, 2026 2:59pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes mo.ui.matplotlib selection masking for plots whose x/y data are datetime-like values by converting datetime arrays into Matplotlib’s internal float date representation before applying selection-bound comparisons (closing #8936).

Changes:

  • Added a _to_numeric() helper in marimo/_plugins/ui/_impl/mpl.py to convert datetime/date/numpy.datetime64 arrays via matplotlib.dates.date2num() before masking.
  • Updated BoxSelection.get_mask() and LassoSelection.get_mask() to use the datetime-aware conversion.
  • Added regression tests covering datetime.datetime and numpy.datetime64 inputs for selection masking.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
marimo/_plugins/ui/_impl/mpl.py Converts datetime-like coordinate arrays to Matplotlib float dates before applying selection comparisons.
tests/_plugins/ui/_impl/test_ui_mpl.py Adds regression tests ensuring box/lasso masks work for datetime and numpy.datetime64 data.

@mscolnick mscolnick merged commit e72c47a into main Mar 31, 2026
43 checks passed
@mscolnick mscolnick deleted the ms/mpl-numbers branch March 31, 2026 18:42
@github-actions
Copy link
Copy Markdown

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.21.2-dev103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interactive selection on charts with datetime values

2 participants