Fix rounding logic in test_field_parameter#12715
Conversation
The previous code was called with outlier_threshold having a typical value of 0.01, which makes polars round to 100 decimal places. This causes almost certain failures when trying to update the snapshot After the change, an outlier_threshold at 0.01 means that we round to 2 decimal place. The snapshot is updated. This snapshot was never valid, as the bug fixed in 9d1325f hid it.
|
@yngve-sk, the change is educated guesswork on how the parameter |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #12715 +/- ##
==========================================
- Coverage 90.64% 90.63% -0.01%
==========================================
Files 431 431
Lines 30113 30113
==========================================
- Hits 27296 27293 -3
- Misses 2817 2820 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
| def round_and_cast_(df: pl.DataFrame) -> pl.DataFrame: | ||
| return df.cast(_schema).with_columns( | ||
| pl.col(pl.Float64).round(int(1 / outlier_threshold)) | ||
| pl.col(pl.Float64).round(int(-math.log10(outlier_threshold))) |
There was a problem hiding this comment.
Nitpick: outlier threshold is always <1 so log10 always negative, but perhaps still do abs instead of -?
There was a problem hiding this comment.
Using - makes it valid without the assumption that outlier_threshold < 1 so I think keeping - makes the code clearer.
yngve-sk
left a comment
There was a problem hiding this comment.
LGTM, only small nitpick suggestion
(Yes the method is quite ad hoc and authored by myself). The Behavior on main:
Behavior in this PR (by simple example):
So summary from a quick call/discussion with @berland : There is probably a better way to do this, ref ERT internal examples comparison. The intent of this is to do an approx comparison of some numbers and update snapshots based on that. It is not at the moment worth pursuing a fix on this beyond what is done in this PR. |
The previous code was called with outlier_threshold having a typical value of 0.01, which makes polars round to 100 decimal places. This causes almost certain failures when trying to update the snapshot
After the change, an outlier_threshold at 0.01 means that we round to 2 decimal place.
The snapshot is updated. This snapshot was never valid, as the bug fixed in 9d1325f hid it.
Issue
Resolves #12713
Approach
🧠
git rebase -i main --exec 'just rapid-tests')When applicable