Repository navigation
fix(utils): preserve mixed-format datetimes during normalization - #46092
JunaidAhamed-7777 wants to merge 2 commits into
Conversation
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| df[col.col_label] = pd.to_datetime( | ||
| df[col.col_label], | ||
| utc=False, | ||
| format="mixed", | ||
| errors="coerce", | ||
| ) |
There was a problem hiding this comment.
Suggestion: When fallback input contains timestamps with different UTC offsets, pandas 3 raises ValueError because utc=False; it escapes normalization and can fail the request.
Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Api mismatch
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/utils/core.py
**Line:** 2160:2165
**Comment:**
*Api Mismatch: When fallback input contains timestamps with different UTC offsets, pandas 3 raises `ValueError` because `utc=False`; it escapes normalization and can fail the request.
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 fixThere was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of ef0492c.
The fallback now catches pandas’ “Mixed timezones” ValueError and retries parsing with utc=True, so timestamps with different offsets can be normalized.
If that's not right, unresolve this thread and CodeAnt will leave it open.
SUMMARY
Preserve valid dates and times when datetime normalization falls back to parsing a column with mixed formats.
When neither a configured format nor a sampled common format is available,
_process_datetime_columnpassesformat=None, exact=Falseto pandas. Pandas infers a format from the first value and applies it to the column. Other valid values can becomeNaT, and a timestamp can lose its time of day without raising an error.Use
format="mixed"in that fallback so each value is parsed using its own format. Omitexact, which pandas does not allow withmixed, and remove the obsolete format-inference warning suppression. Configured formats, cached format mappings, common-format detection, and epoch parsing keep their existing paths.The existing mixed-format test checked warnings and dtype but not the values. Strengthen it and add coverage for reversed row order, null/invalid values, microseconds, timezone conversion, and configured-format precedence. Add a short note to the dataset column documentation.
Nearby work: #45823 changes this helper to handle mixed timezone offsets. Its fallback still uses
format=None, exact=False; this change addresses mixed string formats and does not change timezone policy.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Backend-only change. For
['2023-01-01', '01/02/2023', '2023-03-01 12:00:00']:NaT, March 1 midnight.TESTING INSTRUCTIONS
In a Superset development environment:
Verify that all three dates survive and the third retains noon. Reverse the input order and verify the same timestamps in reverse order.
Local results on Python 3.12.14 and pandas 3.1.0:
8527530aceproduced four regression failures and 25 passes.pre-commit runpassed, including mypy and Ruff. Direct pylint on the changed production file passed with the repository configuration.The full repository suite, docs build, and browser validation were not run.
ADDITIONAL INFORMATION