Repository navigation
fix(charts): render time comparison without a time grain - #42054
Conversation
A time-series chart using a relative time-comparison offset with no time
grain returned a 400 ("Time Grain must be specified when using Time
Comparison") instead of rendering. The validation was introduced as a
side effect of the time-shift join-column rework; before that, grain-less
comparisons joined current against historic timestamps and silently
produced an empty comparison series.
Instead of raising (or restoring the silently-broken raw join), align
grain-less relative offsets exactly: shift the main series' timestamps by
the offset delta and join them against the offset series' raw timestamps,
mirroring the grain-based join without truncation. Joining on stringified
values keeps the merge safe when an empty offset series materializes its
join keys as NaN floats.
Also, as part of this path:
- normalize_time_delta converts quarters to months, since pd.DateOffset
rejects a `quarters` argument (this previously crashed grain-based
quarter offsets too)
- free-form offsets (e.g. "one year ago") that fail the digit-only
grammar are shifted with the same parser used for the offset query's
time range, with a logged fallback when the offset is uninterpretable
- the query's x-axis label picks the temporal join key instead of the
first datetime column
- grain-less joins preserve the original column order, which the
set_index/join/reset_index round-trip otherwise rearranges
Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
Code Review Agent Run #52d6f6
Actionable Suggestions - 1
-
tests/unit_tests/utils/date_parser_tests.py - 1
- Incomplete time unit coverage · Line 567-572
Review Details
-
Files reviewed - 4 · Commit Range:
daae66f..daae66f- superset/models/helpers.py
- superset/utils/date_parser.py
- tests/unit_tests/common/test_time_shifts.py
- tests/unit_tests/utils/date_parser_tests.py
-
Files skipped - 0
-
Tools
- MyPy (Static Code Analysis) - ✔︎ Successful
- Astral Ruff (Static Code Analysis) - ✔︎ Successful
- Whispers (Secret Scanner) - ✔︎ Successful
- Detect-secrets (Secret Scanner) - ✔︎ Successful
Bito Usage Guide
Commands
Type the following command in the pull request comment and save the comment.
-
/review- Manually triggers a full AI review. -
/pause- Pauses automatic reviews on this pull request. -
/resume- Resumes automatic reviews. -
/resolve- Marks all Bito-posted review comments as resolved. -
/abort- Cancels all in-progress reviews.
Refer to the documentation for additional commands.
Configuration
This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].
Documentation & Help
Co-Authored-By: Claude Fable 5 <[email protected]>
|
The 🤖 Generated with Claude Code |
Co-Authored-By: Claude Fable 5 <[email protected]>
The regex matches case-insensitively but preserved the original casing, so "1 QUARTER ago" skipped the quarters-to-months conversion and "1 year AGO" shifted forward instead of back. Co-Authored-By: Claude Fable 5 <[email protected]>
|
The 🤖 Generated with Claude Code |
|
Status update on the unrelated CI failures: the 🤖 Generated with Claude Code |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #42054 +/- ##
==========================================
+ Coverage 64.43% 64.98% +0.54%
==========================================
Files 2747 2751 +4
Lines 153977 154323 +346
Branches 35318 35346 +28
==========================================
+ Hits 99216 100286 +1070
+ Misses 52849 52123 -726
- Partials 1912 1914 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…e-comparison-grain-dd1acc
|
CI is green after the master update. One note on the Codecov patch-coverage number: it understates this PR because of a pre-existing quirk in 🤖 Generated with Claude Code |
Addresses three review findings on the grain-less time comparison fix: - Quarter offsets queried the wrong period: parsedatetime does not understand "N quarters", so get_past_or_future silently left the offset query's window unshifted while the join keys moved back three months, yielding an all-null comparison. Quarter phrases are now rewritten to the equivalent months before parsing, fixing the window for both the grain and grain-less paths (and time_shift handling, which funnels through the same parser). - Unparseable offsets duplicated current data: the same silent parser fallback fetched the current period, and the raw-key join then presented those rows as the comparison series. processing_time_offsets now rejects relative offsets that parse to a zero delta with a validation error (the grain path previously crashed with an unhandled TimeDeltaAmbiguousError on such offsets). - Free-form offsets dropped timezone/sub-second precision: the per-row parser shift rebuilt timestamps at naive second resolution, so shifted keys could never match timezone-aware or fractional-second offset timestamps. Each row's delta is now computed from a truncated copy and applied to the original value; the unparseable-offset probe compares against the truncated value for the same reason. The new processing_time_offsets tests run the real method against a fake query that derives rows from the requested window, so a wrong window fails the test instead of being masked by fabricated frames. Co-Authored-By: Claude Fable 5 <[email protected]>
CodeQL flagged the quarter-rewrite pattern as polynomial: an unbounded digit run followed by a failing match is re-scanned from every suffix. A negative lookbehind restricts match attempts to the start of a digit run and a bounded repetition caps the int() conversion; longer digit runs fall through to parsedatetime like any other unparseable phrase. Co-Authored-By: Claude Fable 5 <[email protected]>
9453ad3 to
feaf01e
Compare
…ilure processing_time_offsets rejects uninterpretable relative offsets with QueryObjectValidationError, which get_df_payload catches and returns as a failed payload, instead of leaking TimeDeltaAmbiguousError as an unhandled exception. Co-Authored-By: Claude Fable 5 <[email protected]>
Code Review Agent Run #c5f563Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
…oundary alignment Replace the per-row ``.map(lambda value: value + delta)`` in the grain-less time-comparison join with vectorized ``DateOffset`` addition over the datetime column (byte-identical output; NaT rows still shift to NaT). Add a docstring note that month/quarter/year offsets clamp to a valid calendar day, so several end-of-month rows can align to one offset timestamp when there is no time grain to truncate against. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Annotate the _QUARTERS_PATTERN module constant, the two new processing_time_offsets test signatures (with a typed Any alias for the MagicMock datasource the tests bind real methods onto), and the caplog fixture parameter. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🎪 Showtime deployed environment on GHA for 5e4f6b6 • Environment: http://35.86.252.225:8080 (admin/admin) |
This reverts commit 41eaa74. Annotating the fixture as QueryContextProcessor resolves _qc_datasource to the Explorable protocol, which does not declare get_offset_custom_or_inherit -- the `processor` fixture binds it (and several other ExploreMixin methods) onto a mock at runtime. The annotation therefore broke mypy: tests/unit_tests/common/test_query_context_processor.py:425: error: "Explorable" has no attribute "get_offset_custom_or_inherit" The tests that reach through _qc_datasource for these bound methods are deliberately left unannotated for this reason. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
🎪 Showtime deployed environment on GHA for 47b829d • Environment: http://54.191.82.136:8080 (admin/admin) |
|
Bito Automatic Review Failed - Technical Failure |
rusackas
left a comment
There was a problem hiding this comment.
Thanks for digging into this, Joe. Nice catch that #39344 turned a dead guard into a regression.
This touches a good chunk of processing_time_offsets and _determine_join_keys though, DST edge cases, quarter-to-month conversion, and free-form offset parsing all folded into one join path.
Bot comments look addressed, LGTM
SUMMARY
A time-series chart using a relative time-comparison offset with no time grain returns HTTP 400
Time Grain must be specified when using Time Comparison.instead of rendering. The validation was introduced as a side effect of #39344, which turned a previously-dead guard into a live one. Before that change, grain-less comparisons didn't error — but they weren't correct either: the join matched current timestamps against historic ones, so the comparison series was silently empty.This PR replaces the error with an exact alignment, so saved charts that started 400-ing render again — and now with a correct comparison series:
-1 yearfor "1 year ago") and joined against the offset series' raw timestamps — the same conventiongenerate_join_columnuses for the grain path, just without truncation. Timestamps with no exact counterpart yield nulls, mirroring the grain-based join. The join uses stringified values so an empty offset series (which materializes join keys as NaN floats) can't crash the merge on a dtype mismatch.normalize_time_deltaconverts quarters to months ("1 quarter ago"→{"months": -3}), sincepd.DateOffsetrejects aquartersargument. This also fixes a pre-existing crash for grain-based quarter offsets ingenerate_join_column."one year ago") that don't matchnormalize_time_delta's digit-only grammar are shifted per-row withget_past_or_future— the same parser that shifted the offset query's time range — instead of silently degrading. If the offset can't be interpreted at all, the join falls back to the raw keys and logs a warning.left_join_df'sset_index().join().reset_index()round-trip moves join keys to the front; the original order is restored so chart payloads and CSV exports don't reorder dimensions.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before:
Screen.Recording.2026-07-16.at.2.41.37.PM.mov
After:
Screen.Recording.2026-07-16.at.2.42.05.PM.mov
TESTING INSTRUCTIONS
pytest tests/unit_tests/common/test_time_shifts.py tests/unit_tests/utils/date_parser_tests.pyADDITIONAL INFORMATION
🤖 Generated with Claude Code