Extract common pattern in comparison stat functions to reduce CCN#267
Extract common pattern in comparison stat functions to reduce CCN#267
Conversation
…r function Co-authored-by: talgalili <976006+talgalili@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors five comparison statistic methods (_asmd_BalanceDF, _kld_BalanceDF, _emd_BalanceDF, _cvmd_BalanceDF, _ks_BalanceDF) in the BalanceDF class to reduce code duplication and cyclomatic complexity by extracting a common pattern into a new helper method _apply_comparison_stat_to_BalanceDF.
Changes:
- Introduced
_apply_comparison_stat_to_BalanceDFhelper that centralizes validation, data extraction, and delegation to comparison functions - Refactored five static methods to use the helper, reducing each from ~15 lines to ~5 lines
- Added
Callableto the typing imports for proper type hinting
|
@copilot apply changes based on the comments in this thread |
…lanceDF, and _ks_BalanceDF Co-authored-by: talgalili <976006+talgalili@users.noreply.github.com>
|
Fix Run flake8 . |
Co-authored-by: talgalili <976006+talgalili@users.noreply.github.com>
|
@copilot fix Run ufmt check . |
Co-authored-by: talgalili <976006+talgalili@users.noreply.github.com>
|
@talgalili has imported this pull request. If you are a Meta employee, you can view this in D90870323. |
|
@talgalili merged this pull request in c7fcb79. |
_apply_comparison_stat_to_BalanceDFto reduce code duplication_asmd_BalanceDFto use the new helper function_kld_BalanceDFto use the new helper function_emd_BalanceDFto use the new helper function_cvmd_BalanceDFto use the new helper function_ks_BalanceDFto use the new helper functionSummary
Successfully extracted the common pattern from five similar functions (
_asmd_BalanceDF,_kld_BalanceDF,_emd_BalanceDF,_cvmd_BalanceDF,_ks_BalanceDF) into a single generic helper function_apply_comparison_stat_to_BalanceDF.Changes Made
Callableto the imports fromtypingmodule_apply_comparison_stat_to_BalanceDFhelper function that:_asmd_BalanceDFwhich passesstd_type="target"via kwargstest_BalanceDF__kld_BalanceDF: Direct test of _kld_BalanceDF methodtest_BalanceDF__emd_BalanceDF: Direct test of _emd_BalanceDF methodtest_BalanceDF__cvmd_BalanceDF: Direct test of _cvmd_BalanceDF methodtest_BalanceDF__ks_BalanceDF: Direct test of _ks_BalanceDF methodtest_BalanceDF_comparison_functions_invalid_input: Tests input validation for all methodsTest Coverage
Benefits
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.