Conversation
Two defects in the diff engine produced wrong change summaries: _diff_by_position() seeded rows_added with abs(len(new) - len(old) and only overwrote it when the new frame was longer. When rows were removed (old=5, new=3) the result was rows_added=2, rows_removed=2 instead of 0 added and 2 removed, double-counting deletions as additions. Both counters are now clamped independently with max(0, ...). _diff_by_key() compared cells with `!=`, which is not a valid equality test for DataFrame values: `nan != nan` is True, so a row whose value did not change was counted as modified whenever the column was nullable, and comparing `pd.NA` yields `pd.NA`, whose truth value raises TypeError. This is reachable on the DuckLake path, which writes nullable dtypes. Comparisons now go through _values_differ(), which checks missingness before falling back to `!=`, treating two missing cells as equal and a missing/present pair as a change. _is_missing() is factored out and tolerates values pd.isna cannot reduce to a scalar.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #349 +/- ##
=======================================
Coverage ? 97.19%
=======================================
Files ? 180
Lines ? 22773
Branches ? 0
=======================================
Hits ? 22134
Misses ? 639
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
🎉 This PR is included in version 2.11.6 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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
Two defects in
pysus/api/diff/comparison.pyproduced incorrect change summaries.1. Positional diff invented additions when rows were removed
_diff_by_position()seededrows_addedwithabs(len(df_new) - len(df_old))and only overwrote it inside theif len(df_new) > len(df_old)branch:With
old=5, new=3this yieldsrows_added=2, rows_removed=2. The correct result is0added and2removed, so every deletion was double-counted. Both counters are now computed independently withmax(0, ...).2.
!=was used as an equality test on DataFrame cellsfloat("nan") != float("nan")isTrue, so a row that did not change was counted as modified whenever the value was NULL in both frames.pd.NA) the comparison returnspd.NA, andif pd.NA:raisesTypeError. The DuckLake path writes nullable dtypes, so this is reachable in normal use.Comparisons now route through
_values_differ(), which checks missingness before falling back to!=— two missing cells compare equal, a missing/present pair is a change._is_missing()is factored out and tolerates valuespd.isna()cannot reduce to a scalar.Tests
Added 9 tests to
pysus/tests/api/test_diff.pycovering shrinking frames, growing frames, equal-length frames,nanin both frames, null→value and value→null transitions, and nullableInt64dtypes in both directions.1742 passed, 6 skipped(was1733 passed, 6 skipped)blackandisortcleanNote
No behavior outside the two diff functions is changed.