Repository navigation
fix(charts): fix time comparison crash when offsets share a numeric prefix - #39344
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #39344 +/- ##
==========================================
+ Coverage 63.73% 64.30% +0.57%
==========================================
Files 2652 2652
Lines 144799 144804 +5
Branches 33415 33418 +3
==========================================
+ Hits 92289 93118 +829
+ Misses 50849 50023 -826
- Partials 1661 1663 +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:
|
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #20d49bActionable 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 |
Code Review Agent Run #863a77Actionable 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 |
Code Review Agent Run #8072a7Actionable 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 |
|
@mistercrunch looks like this may need a rebase. |
df1fa61 to
95ad8b8
Compare
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #851741Actionable 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 |
Code Review Agent Run #771afcActionable 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 |
The `endswith(ts)` check in `get_column_groups` matched columns
incorrectly when time shifts shared a numeric suffix — e.g.
"metric__22 weeks ago".endswith("2 weeks ago") returned True,
causing columns to be misclassified. Use `endswith(TIME_COMPARISON + ts)`
to include the "__" separator in the match.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
…grain Without a time grain, the offset join columns that align shifted dates to original dates are never created. The join falls back to raw column values, producing silently wrong results (identical values instead of shifted data). Replace the existing dead-code validation with a check that raises a helpful error early. Co-Authored-By: Claude Opus 4.6 <[email protected]>
When a DataFrame has duplicate column names (e.g. from time comparison post-processing), `df[column]` returns a DataFrame instead of a Series. Calling `.isna().all()` on a DataFrame produces a Series of booleans, which raises "truth value of a Series is ambiguous" in the `if` check. Fix by using positional indexing (`df.iloc[:, i]`) to always retrieve a single Series regardless of duplicate column names. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…offsets The `includes(offset)` substring match caused "11 year ago" to match "1 year ago", producing duplicate column names that crash the backend with "truth value of a Series is ambiguous". Switch to `endsWith` with the `__` separator prefix for exact offset matching. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Refine the time grain validation to check whether the first join key is a datetime column before raising. Table charts with time comparison use non-temporal dimension joins that work without a time grain. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…fset.ts 1. Check any join key (not just the first) for temporal dtype when validating time grain requirement. Fixes edge case where temporal key is not the first in the join_keys list. 2. Fix substring matching bugs in timeOffset.ts: - getTimeOffset: use startsWith for <offset>, pattern - getOriginalSeries: use startsWith+slice for <offset>, pattern Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Address CodeAnt AI review comment — add explicit -> None return type annotation to test_extract_dataframe_dtypes_with_duplicate_columns. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Auto-format renameOperator.ts (prettier) and test_time_shifts.py (ruff-format) to pass CI pre-commit checks. Co-Authored-By: Claude Opus 4.6 <[email protected]>
89f9ca7 to
02428e4
Compare
Code Review Agent Run #04fc43Actionable Suggestions - 0Additional Suggestions - 1
Review 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 |
rusackas
left a comment
There was a problem hiding this comment.
Nice, @mistercrunch, LGTM. Separator-aware endsWith('__' + offset) and the positional df.iloc[:, i] are the right way to kill the duplicate-column ambiguity, and the clearer time-grain guard is a nice bonus. Thanks!
SUMMARY
Charts using time comparison with offsets that share a numeric prefix (e.g. "1 year ago" and "11 year ago", or "2 weeks ago" and "22 weeks ago") would crash with "The truth value of a Series is ambiguous". The root cause was substring matching (
includes/endswith) that incorrectly matched one offset as a suffix of another.This PR fixes the issue across multiple layers:
Frontend
renameOperator.ts(root cause):metricWithOffset.includes(offset)matched"Births__11 year ago"with"1 year ago", producing duplicate column names in the rename mapping. Fixed withendsWith(__offset).Backend
contribution.py:col.endswith(ts)had the same substring issue for time shift column grouping. Fixed withendsWith(TIME_COMPARISON + ts).Backend
core.py:extract_dataframe_dtypescrashed when duplicate column names causeddf[column]to return a DataFrame instead of a Series. Fixed with positional indexing (df.iloc[:, i]).Backend
helpers.py: Added validation that raises a helpful "Time Grain must be specified when using Time Comparison" error when a temporal join key is used without time grain, instead of the cryptic pandas error. The check is scoped to temporal join keys only, so table charts with non-temporal dimension joins continue to work.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
TESTING INSTRUCTIONS
Unit tests:
```bash
Backend
pytest tests/unit_tests/pandas_postprocessing/test_contribution.py -v
pytest tests/unit_tests/common/test_time_shifts.py -v
pytest tests/unit_tests/utils/test_core.py::test_extract_dataframe_dtypes_with_duplicate_columns -v
Frontend
npx jest packages/superset-ui-chart-controls/test/operators/renameOperator.test.ts --no-coverage
```
ADDITIONAL INFORMATION
🤖 Generated with Claude Code