fix: support datetime values in mo.ui.matplotlib selection masks#8940
Merged
fix: support datetime values in mo.ui.matplotlib selection masks#8940
mo.ui.matplotlib selection masks#8940Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
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 inmarimo/_plugins/ui/_impl/mpl.pyto convertdatetime/date/numpy.datetime64arrays viamatplotlib.dates.date2num()before masking. - Updated
BoxSelection.get_mask()andLassoSelection.get_mask()to use the datetime-aware conversion. - Added regression tests covering
datetime.datetimeandnumpy.datetime64inputs 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. |
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.21.2-dev103 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #8936
BoxSelection.get_mask()andLassoSelection.get_mask()raisedTypeErrorwhen users passeddatetimeobjects as x/y coordinates. The selection bounds from the frontend are matplotlib's internal float representation of dates, but comparingdatetime >= floatfails.Added a
_to_numeric()helper that detects datetime arrays (datetime.datetime,datetime.date,numpy.datetime64) and converts them to matplotlib's float representation viadate2num()before comparison.