Commit e0c42be
UT Coverage for cbps.py
Summary:
## Summary:
This diff improves test coverage for `fbcode/core_stats/balance/weighting_methods/cbps.py` by adding comprehensive unit tests. The changes include:
**Test Coverage Improvements:**
- Added tests for CBPS 'exact' method behavior with tight constraints
- Added tests for invalid method parameter validation
- Added tests for balance_classes=False option
- Added tests for DataFrame input handling in helper functions
- Added tests for different scipy optimization methods
- Added tests for GMM optimization result selection
- Added tests for various edge cases and error conditions
- Added tests for weight trimming with percentile method
**Code Quality Improvements:**
- Enhanced type annotations using Optional[T] instead of Union[T, None]
- Improved docstring formatting for better readability
- Fixed deprecated pandas functions (using pd.concat instead of append)
- Added DataFrame to numpy array conversion in gmm_function to handle pandas inputs correctly
- Ensured consistent handling of array and DataFrame inputs
**Test Fixes Applied:**
- Updated test_cbps_exact_method_with_constraint_violation to verify weights become identical instead of expecting exception
- Modified test_cbps_with_weight_trimming_percentile to test percentile trimming functionality correctly
Differential Revision: D89150493
fbshipit-source-id: 4e676e7943969f1e2963619a72d495cebd5d2a171 parent 7dd4610 commit e0c42be
2 files changed
Lines changed: 451 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
| |||
129 | 132 | | |
130 | 133 | | |
131 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
132 | 143 | | |
133 | 144 | | |
134 | 145 | | |
| |||
0 commit comments