fix(streaming,cdc): compare mixed tz-awareness in UTC; flag implausible inferred epoch event times - #421
Merged
Conversation
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
FreshData benchmark report —
|
| fixture | n_rows | n_cols | p50 s | p95 s | peak MB | repair % | false-repair % | preserve % | trust | monotonic | export % |
|---|
Authored-code reduction (Metric 6)
…le inferred epoch event times StreamingCleaner folded each batch's datetime min/max and the time-series watermarks with plain comparisons, so a batch whose tz-awareness differed from the first (including naive then mixed-offset strings) raised TypeError. Compare in UTC, reading naive values as UTC, and warn when awareness changes between time-series batches. infer_epoch_unit picks a unit from the median magnitude only, so row numbers were read as epoch seconds and cdc_profile reported a 56-year-old batch as fresh and passing. When the unit is inferred and the median instant is before 1990-01-01, cdc_profile now reports an event_time_implausible error and skips freshness, lateness and ordering; time-series cleaning warns. An explicit event_time_unit/timestamp_unit still forces the unit.
kevincostner17
force-pushed
the
fix/streaming-event-time-tz-and-epoch
branch
from
September 15, 2026 16:57
d80ad78 to
47e269a
Compare
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.
Summary
This PR fixes two event-time bugs:
StreamingCleanerraisedTypeError: Cannot compare tz-naive and tz-aware timestampswhen a datetime column changed tz-awareness between batches.cdc_profileread small numbers such as row numbers1..100as epoch seconds, then reported a 56-year-old batch as passing with no warning.Root cause
ColumnState._update_datetime(streaming/_state.py) folded each batch's datetime min/max into the running state with plainmin()/max()/<. The time-series watermarks (TimeSeriesProcessor._late_mask) did the same. The first batch fixed whether the stored value was tz-naive or tz-aware, so a later batch of the other kind raised on comparison. That includes a naive batch followed by strings with mixed UTC offsets, which parse to UTC.infer_epoch_unitpicks a unit from the median magnitude alone, so any number below 1e11 is read as seconds.cdc_profilethen computed freshness, lateness and ordering from those instants as if they were real.Behaviour change
fieldcheck._as_utc.state_marks that columntz_mixed.cdc_profilereports anevent_time_implausibleerror. It skips freshness (freshness_secondsisNone), lateness and ordering. Key, duplicate, operation and missing-value checks still run.event_time_unit=/timestamp_unit=still forces the unit and skips the check.Default-output changes
cdc_profile, for a numeric event-time column whose unit is inferred and whose median is before 1990-01-01 (row numbers, counters, zeros, negatives, small floats, or real epoch values from 1970–1989):event_time_implausibleat levelerror, withdetailskeysinferred_unit,medianandplausible_from. TheDefectKindliteral gains"event_time_implausible".passedgoes True → False, andn_errorsrises by 1.freshness_secondschanges from a float toNone, andsummary()omits the freshness line.late/out_of_order/staledefects are no longer reported, andreplay_riskcounts late rows as 0.freshnessandorderingtrust penalties are 0.0.to_frame(),to_dict()andto_json()gain the new defect row.fd.clean_timeseries/ time-seriesStreamingCleaner, for a numeric timestamp or event-time column with an inferred unit and a median before 1990-01-01: a newreport.warningsentry. Parsing, rows and actions are unchanged.StreamingCleanerwith batches of mixed tz-awareness:TypeError. This input used to crash.report.warningsentry.state_["columns"][col]["datetime"]gains"tz_mixed": True, only for columns that saw both kinds.cdc_profilewithevent_time_implausibleunlessevent_time_unit=is passed explicitly.datetime64columns are unaffected.cdc_profile.Tests
tests/test_streaming_state.py:tz_mixedkey when awareness never changestests/test_streaming_timeseries.py:StreamingCleaner: late-row counts, the watermark in its arrival zone, the awareness warning, andstate_["columns"][col]["datetime"]["tz_mixed"]timestamp_unitoverridetests/test_cdc_profile_fixes.py:event_time_implausible,passed=Falseand no freshnessInt64column, with and without a watermarkevent_time_unit="s"still reads small numbers as epochsVerification
ruff check .: passedmypy src/freshdata: no issues in 205 source filespytest -m "not online and not large":