Skip to content

fix(dataset): convert timezone-aware values with the dataset timezone - #45344

Merged
rusackas merged 2 commits into
apache:masterfrom
porkedchop:fix/dataset-timezone-tz-aware
Oct 20, 2026
Merged

rusackas merged 2 commits into
apache:masterfrom
porkedchop:fix/dataset-timezone-tz-aware

Conversation

@porkedchop

Copy link
Copy Markdown
Contributor

SUMMARY

#37014 added a dataset timezone ("timezone" in the dataset's extra). normalize_dttm_col applies it by localizing the column to UTC and then converting it to that timezone.

That assumes the values are naive. Columns of a timezone-aware type, like Postgres timestamptz, BigQuery TIMESTAMP or ClickHouse DateTime64 with a zone, come out of SupersetResultSet as datetime64[ns, tz], and tz_localize("UTC") raises TypeError: Already tz-aware, use tz_convert to convert. on them. So once a timezone is set on such a dataset, charts that return the column fail.

This only localizes naive values to UTC and converts tz-aware values as they are. Naive columns behave the same as before.

This touches the same block as #45203 (DATE columns), but the two changes are independent.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

  1. On a Postgres dataset with a timestamptz column, set the dataset extra to {"timezone": "America/New_York"}.
  2. Build a table chart that includes the column.
  3. Before: the chart fails with "Already tz-aware". After: the values are shown in New York time.

pytest tests/unit_tests/utils/test_core.py -k tz_aware fails on master and passes with this change.

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

normalize_dttm_col applies the dataset timezone by localizing the column
to UTC and converting it. Columns read from a timezone-aware type
(Postgres timestamptz, BigQuery TIMESTAMP, ClickHouse DateTime64 with a
zone) already reach the dataframe as tz-aware, and tz_localize raises
"Already tz-aware" on them, so any chart that returns such a column
errors once the dataset has a timezone set. Only localize naive values
and convert the rest as they are.
Comment thread superset/utils/core.py
Comment on lines +2191 to +2195
(
series.dt.tz_localize("UTC")
if series.dt.tz is None
else series
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: When mixed UTC offsets produce an object-dtype series, series.dt.tz raises AttributeError, so charts with those values fail instead of converting.

Assessment: 🟠 Major · 🔁 Occurrence: Rarely · 🏷️ Type error

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/utils/core.py
**Line:** 2191:2195
**Comment:**
	*Type Error: When mixed UTC offsets produce an object-dtype series, `series.dt.tz` raises `AttributeError`, so charts with those values fail instead of converting.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt PR Risk: Medium Risk

  • The PR needs attention before merging.
  • Mixed-offset datetime values can produce object-dtype columns, for which the .dt access in normalize_dttm_col fails; verify this case is handled.

Assessed commit: 538d5ac206e7

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.45%. Comparing base (4c546ed) to head (538d5ac).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #45344   +/-   ##
=======================================
  Coverage   83.45%   83.45%           
=======================================
  Files        3045     3045           
  Lines      199148   199181   +33     
  Branches    46438    46445    +7     
=======================================
+ Hits       166199   166235   +36     
+ Misses      29723    29720    -3     
  Partials     3226     3226           
Flag Coverage Δ
hive 35.00% <ø> (-0.01%) ⬇️
mysql 52.97% <ø> (-0.01%) ⬇️
postgres 52.97% <ø> (-0.01%) ⬇️
presto 36.76% <ø> (-0.01%) ⬇️
python 86.97% <ø> (+<0.01%) ⬆️
sqlite 52.73% <ø> (-0.01%) ⬇️
unit 80.99% <ø> (+<0.01%) ⬆️

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.

@sadpandajoe
sadpandajoe requested review from rusackas and sadpandajoe and a balanced review from Copilot October 15, 2026 17:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open findings
What changed in this PR

Fixes normalize_dttm_col failing on timezone-aware datetime columns when a dataset timezone is configured, by converting tz-aware values instead of re-localizing them.

Changes:

  • Update timezone handling in normalize_dttm_col to only tz_localize("UTC") for tz-naive series while converting tz-aware series directly.
  • Add a unit test covering tz-aware datetime inputs to prevent regressions.
File Description
tests/​unit_tests/​utils/​test_core.py Adds coverage for tz-aware datetime series conversion behavior.
superset/​utils/​core.py Prevents Already tz-aware errors by conditional localize vs convert logic.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread superset/utils/core.py
Comment on lines 2184 to 2198
tz = ZoneInfo(_col.timezone)
# Data is stored in UTC, convert to the dataset's configured timezone
# First make the datetime UTC-aware, then convert to target timezone
series = df[_col.col_label]
if not series.empty and series.notna().any():
# Convert UTC to target timezone
df[_col.col_label] = (
series.dt.tz_localize("UTC")
(
series.dt.tz_localize("UTC")
if series.dt.tz is None
else series
)
.dt.tz_convert(tz)
.dt.tz_localize(None) # Remove timezone info for display
)

normalize_dttm_col(df, dttm_cols)

assert is_datetime64_dtype(df["date_col"])
@pull-request-size pull-request-size Bot added size/M and removed size/S labels Oct 15, 2026
@netlify

netlify Bot commented Oct 15, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 538d5ac
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6ad12df43d18bde6bf0f4dd0
😎 Deploy Preview https://deploy-preview-45344--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.

@rusackas
rusackas merged commit 152e1e9 into apache:master Oct 20, 2026
79 checks passed
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.

4 participants