fix(streaming): real recent-window dedup, dtype-stable row hashes, drift for constant columns - #357
Open
kevincostner17 wants to merge 1 commit into
Open
kevincostner17 wants to merge 1 commit into
kevincostner17 wants to merge 1 commit into
Conversation
…t-column drift global_duplicates kept the first window_size rows forever (#292). The cross-batch hash set only accepted new hashes while it had room and never evicted, so once window_size distinct rows had been seen it stopped remembering, and duplicates of recent rows passed through for the rest of the stream. The window is now an OrderedDict: a repeated row is moved to the most-recent end, new rows are appended, and the least recently seen rows are evicted once the window exceeds window_size. Membership is still checked against earlier batches only, so within-batch duplicate handling is unchanged. Cross-batch duplicates were missed when a numeric column flipped between int64 and float64 (#293), e.g. an integer column promoted by a missing value, because hash_pandas_object hashes dtype-specific bytes. Rows are now hashed from a canonical frame: numeric non-bool columns, nullable ones included, are hashed as float64 with missing values as NaN and -0.0 as 0.0. Integer columns holding a value beyond +/-2**53 keep their own dtype so distinct large integers are not merged. Distribution drift never fired for a column that had been constant (#294), because the z-score check returned early when the running std was 0. For a constant column with at least two prior values, drift is now reported (high risk, kind "distribution") when the batch mean leaves the constant by more than 1e-9 * max(1, |mean|). The seen-hash window is in-memory only and is not part of state_, StreamingState.to_dict() or any checkpoint, so there is no serialized format to migrate. Closes #292 Closes #293 Closes #294
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)
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
Fixes three streaming bugs in
StreamingCleaner.global_duplicateskept the firstwindow_sizerows forever.window_sizedistinct rows, duplicates of recent rows passed through for the rest of the stream.OrderedDict. A repeated row moves to the most-recent end, and the least recently seen rows are evicted, so it is the bounded recent window the docs describe.hash_pandas_objecthashes dtype-specific bytes, so1and1.0hashed differently (for example, an int column promoted to float by a missing value).-0.0as0.0.1e-9 * max(1, |mean|)is now reported as high-riskdistributiondrift.Docstrings for
global_duplicatesanddrift_zscore, anddocs/streaming.md, are updated to match.Behaviour changes:
drift_logentry.state_,StreamingState.to_dict()or any checkpoint.Tests
New module
tests/test_streaming_dedup_drift.py(15 tests):window_sizedistinct rowsInt64vs float-0.0vs010 of the 15 fail on
main; the other 5 guard against false positives.Verification
ruff check .: all checks passedmypy src/freshdata: no issues in 202 source filespytest -m "not online and not large", py3.12 / pandas 2.3: 4254 passed, 6 skippedpytest -m "not online and not large", py3.9 / pandas 1.5: 4250 passed, 10 skippedCloses #292
Closes #293
Closes #294