Skip to content

fix(charts): fix time comparison crash when offsets share a numeric prefix - #39344

Merged
rusackas merged 9 commits into
masterfrom
sc-103393-time-comparison-chart-fail
Jul 8, 2026
Merged

rusackas merged 9 commits into
masterfrom
sc-103393-time-comparison-chart-fail

Conversation

@mistercrunch

@mistercrunch mistercrunch commented Apr 14, 2026 •

Copy link
Copy Markdown
Member

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:

  1. 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 with endsWith(__offset).

  2. Backend contribution.py: col.endswith(ts) had the same substring issue for time shift column grouping. Fixed with endsWith(TIME_COMPARISON + ts).

  3. Backend core.py: extract_dataframe_dtypes crashed when duplicate column names caused df[column] to return a DataFrame instead of a Series. Fixed with positional indexing (df.iloc[:, i]).

  4. 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

  1. Create a time-series line chart with two time comparison offsets where one is a numeric prefix of the other (e.g. "1 year ago" and "11 year ago")
  2. Verify the chart renders correctly with distinct series for each offset
  3. Verify a table chart with time comparison and no time grain still works (non-temporal join)
  4. Verify that removing time grain from a time-series chart with time comparison shows a helpful error

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

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

@codecov

codecov Bot commented Apr 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.30%. Comparing base (d51d988) to head (02428e4).

Files with missing lines Patch % Lines
superset/models/helpers.py 0.00% 5 Missing and 1 partial ⚠️
...perset/utils/pandas_postprocessing/contribution.py 50.00% 1 Missing ⚠️
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     
Flag Coverage Δ
hive 39.33% <10.00%> (-0.01%) ⬇️
javascript 68.45% <100.00%> (+<0.01%) ⬆️
mysql 58.03% <30.00%> (-0.01%) ⬇️
postgres 58.09% <30.00%> (-0.01%) ⬇️
presto 40.90% <30.00%> (-0.01%) ⬇️
python 59.54% <30.00%> (+1.22%) ⬆️
sqlite 57.72% <30.00%> (-0.01%) ⬇️
unit 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mistercrunch
mistercrunch marked this pull request as ready for review April 21, 2026 02:38
@dosubot dosubot Bot added the change:backend Requires changing the backend label Apr 21, 2026
@netlify

netlify Bot commented Apr 21, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 85bb879
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69e6eb3ce08e5b00080f4b20
😎 Deploy Preview https://deploy-preview-39344--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread superset/models/helpers.py Resolved
@bito-code-review

bito-code-review Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #20d49b

Actionable Suggestions - 0
Review Details
  • Files reviewed - 8 · Commit Range: 287c1bd..88ad736
    • superset-frontend/packages/superset-ui-chart-controls/src/operators/renameOperator.ts
    • superset-frontend/packages/superset-ui-chart-controls/test/operators/renameOperator.test.ts
    • superset/models/helpers.py
    • superset/utils/core.py
    • superset/utils/pandas_postprocessing/contribution.py
    • tests/unit_tests/common/test_time_shifts.py
    • tests/unit_tests/pandas_postprocessing/test_contribution.py
    • tests/unit_tests/utils/test_core.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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

AI Code Review powered by Bito Logo

@mistercrunch mistercrunch changed the title fix(charts): use separator-aware matching for time shift column grouping fix(charts): fix time comparison crash when offsets share a numeric prefix Apr 21, 2026
@bito-code-review

bito-code-review Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #863a77

Actionable Suggestions - 0
Review Details
  • Files reviewed - 4 · Commit Range: 88ad736..e7491e0
    • superset/models/helpers.py
    • tests/unit_tests/common/test_time_shifts.py
    • superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/timeOffset.ts
    • superset-frontend/packages/superset-ui-chart-controls/test/operators/utils/timeOffset.test.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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

AI Code Review powered by Bito Logo

Comment thread tests/unit_tests/utils/test_core.py Resolved
Comment thread superset/models/helpers.py Resolved
@bito-code-review

bito-code-review Bot commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #8072a7

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: e7491e0..df1fa61
    • tests/unit_tests/common/test_time_shifts.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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

AI Code Review powered by Bito Logo

@sadpandajoe

Copy link
Copy Markdown
Member

@mistercrunch looks like this may need a rebase.

@mistercrunch
mistercrunch force-pushed the sc-103393-time-comparison-chart-fail branch from df1fa61 to 95ad8b8 Compare May 6, 2026 19:54
@netlify

netlify Bot commented May 6, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 95ad8b8
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69fb9c8818f81700080a5ed1
😎 Deploy Preview https://deploy-preview-39344--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented May 6, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit b893645
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69fb9cbf370408000815a978
😎 Deploy Preview https://deploy-preview-39344--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@bito-code-review

bito-code-review Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #851741

Actionable Suggestions - 0
Review Details
  • Files reviewed - 10 · Commit Range: 6c00ee2..b893645
    • superset-frontend/packages/superset-ui-chart-controls/src/operators/renameOperator.ts
    • superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/timeOffset.ts
    • superset-frontend/packages/superset-ui-chart-controls/test/operators/renameOperator.test.ts
    • superset-frontend/packages/superset-ui-chart-controls/test/operators/utils/timeOffset.test.ts
    • superset/models/helpers.py
    • superset/utils/core.py
    • superset/utils/pandas_postprocessing/contribution.py
    • tests/unit_tests/common/test_time_shifts.py
    • tests/unit_tests/pandas_postprocessing/test_contribution.py
    • tests/unit_tests/utils/test_core.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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

AI Code Review powered by Bito Logo

@bito-code-review

bito-code-review Bot commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #771afc

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: b893645..89f9ca7
    • superset-frontend/packages/superset-ui-chart-controls/src/operators/renameOperator.ts
    • tests/unit_tests/common/test_time_shifts.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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

AI Code Review powered by Bito Logo

mistercrunch and others added 8 commits June 16, 2026 19:26
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]>
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]>
@yousoph
yousoph force-pushed the sc-103393-time-comparison-chart-fail branch from 89f9ca7 to 02428e4 Compare June 16, 2026 19:27
@bito-code-review

bito-code-review Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #04fc43

Actionable Suggestions - 0
Additional Suggestions - 1
  • tests/unit_tests/utils/test_core.py - 1
    • Weak test assertion on dtype values · Line 1833-1837
      The test only asserts `len(result) == 3` but doesn't verify the actual types. Per BITO.md rule [6262], tests should verify actual behavior, not just that a function doesn't crash. Add assertions on the returned `GenericDataType` values to ensure correctness.
      Code suggestion
      --- tests/unit_tests/utils/test_core.py (lines 1833-1837)
      +def test_extract_dataframe_dtypes_with_duplicate_columns() -> None:
      +    """extract_dataframe_dtypes should not crash on duplicate column names."""
      +    from superset.utils.core import GenericDataType
      +    df = pd.DataFrame([[1, 2, 3]], columns=["a", "b", "a"])
      +    result = extract_dataframe_dtypes(df)
      +    assert len(result) == 3
      +    assert result == [GenericDataType.NUMERIC, GenericDataType.NUMERIC, GenericDataType.NUMERIC]
Review Details
  • Files reviewed - 10 · Commit Range: 0c06c2f..02428e4
    • superset-frontend/packages/superset-ui-chart-controls/src/operators/renameOperator.ts
    • superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/timeOffset.ts
    • superset-frontend/packages/superset-ui-chart-controls/test/operators/renameOperator.test.ts
    • superset-frontend/packages/superset-ui-chart-controls/test/operators/utils/timeOffset.test.ts
    • superset/models/helpers.py
    • superset/utils/core.py
    • superset/utils/pandas_postprocessing/contribution.py
    • tests/unit_tests/common/test_time_shifts.py
    • tests/unit_tests/pandas_postprocessing/test_contribution.py
    • tests/unit_tests/utils/test_core.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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

AI Code Review powered by Bito Logo

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants