Fix strpfromiso silently corrupting non-UTC timestamps#562
Open
mittalpk wants to merge 1 commit into
Open
Conversation
…-intelligence-solutions#561) fix_naivety() used replace(tzinfo=timezone.utc) on already-aware datetimes, which relabels the timezone without converting the wall-clock value. A timestamp like 2026-07-23T10:00:00+05:00 (05:00 UTC) was silently stored as 2026-07-23T10:00:00+00:00, shifted by the source offset. Fix: only relabel (assume UTC) when the parsed value has no offset at all; convert via astimezone() when it does, matching the already-correct tz_convert("UTC") behavior in the sibling fix_dataframe_column() function. Adds regression tests covering positive/negative offsets, the existing Z-suffix path, naive input, and the aware-disabled branch. Signed-off-by: Praveen Mittal <pkmittal28@gmail.com>
Contributor
|
Dear @mittalpk thank you for your report. Could you start the contribution level agreement as in https://processintelligence.solutions/pm4py/contributing ? |
Author
|
Thanks @fit-alessandro-berti |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #561
Summary
strpfromiso(the default ISO8601 date parser for Python >= 3.7) silently corrupts any timestamp that has a non-UTC offset, wheneverENABLE_DATETIME_COLUMNS_AWAREis enabled — which is the default for everyone except cuDF/RAPIDS installs.fix_naivety()calleddt.replace(tzinfo=timezone.utc)on an already-aware datetime.replace()only relabels the timezone; it does not convert the wall-clock value. A timestamp like2026-07-23T10:00:00+05:00(which is05:00 UTC) was silently stored as2026-07-23T10:00:00+00:00— shifted by 5 hours, with no warning or error.Fix
Only relabel (assume UTC) when the parsed value has no offset at all (nothing to convert from — same behavior as before for naive input). When it does have an offset, convert via
astimezone(timezone.utc), matching the already-correcttz_convert("UTC")behavior in the siblingfix_dataframe_column()function a few lines above it in the same file.Testing
Added
tests/dt_parsing_test.pycovering:Z-suffix path (still correct)ENABLE_DATETIME_COLUMNS_AWARE = Falsebranch (unchanged)Verified the two offset-conversion tests fail against the pre-fix code and pass against the fix. Also ran the existing
business_hours_test.pyandxes_impexp_test.py/xes_deep_coverage_test.pysuites (downstream consumers of this parser) — all pass, no regressions.How did I verify:
python -m pytest tests/dt_parsing_test.py tests/business_hours_test.py tests/xes_impexp_test.py tests/xes_deep_coverage_test.py -vfrom thetests/directory, all green.