Spaces:
Running
Running
| import pandas as pd | |
| from scripts.audit_multi_factor_calculation import ( | |
| build_factor_warnings, | |
| summarize_factor_series, | |
| ) | |
| def test_summarize_factor_series_reports_coverage_and_range(): | |
| summary = summarize_factor_series(pd.Series([-1.0, 0.0, 0.5, 2.0, float("nan")])) | |
| assert summary["n"] == 5 | |
| assert summary["finite_n"] == 4 | |
| assert summary["nonfinite_count"] == 1 | |
| assert summary["zero_pct"] == 0.25 | |
| assert summary["nonzero_pct"] == 0.75 | |
| assert summary["positive_pct"] == 0.5 | |
| assert summary["negative_pct"] == 0.25 | |
| assert summary["out_of_range_count"] == 1 | |
| assert summary["all_zero"] is False | |
| def test_build_factor_warnings_flags_inert_and_out_of_range_factors(): | |
| warnings = build_factor_warnings( | |
| { | |
| "all_zero": { | |
| "nonfinite_count": 0, | |
| "out_of_range_count": 0, | |
| "all_zero": True, | |
| "nonzero_pct": 0.0, | |
| }, | |
| "sparse": { | |
| "nonfinite_count": 0, | |
| "out_of_range_count": 0, | |
| "all_zero": False, | |
| "nonzero_pct": 0.01, | |
| }, | |
| "bad_range": { | |
| "nonfinite_count": 0, | |
| "out_of_range_count": 3, | |
| "all_zero": False, | |
| "nonzero_pct": 0.5, | |
| }, | |
| } | |
| ) | |
| assert any("all_zero: all values are zero" in warning for warning in warnings) | |
| assert any("sparse: non-zero coverage" in warning for warning in warnings) | |
| assert any("bad_range: has 3 values outside" in warning for warning in warnings) | |