Fix prop_above_and_below typing and empty concat handling#353
Fix prop_above_and_below typing and empty concat handling#353neuralsorcerer wants to merge 3 commits intofacebookresearch:mainfrom
prop_above_and_below typing and empty concat handling#353Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes the prop_above_and_below() function in balance/stats_and_plots/weights_stats.py by:
- Replacing the untyped
dict[Any, Any]return type with a newPropAboveBelowResultTypedDict. - Adding
@overloadsignatures to let static type checkers narrow the return type based on thereturn_as_seriesliteral argument. - Fixing a latent bug where
pd.concatcould be called with an all-Nonelist (when one ofbelow/aboveisNone) by building thepieceslist with only non-None Series.
Changes:
- Introduced
PropAboveBelowResultTypedDict and@overloadsignatures forprop_above_and_below, plus a safe concat fix when only one threshold group is provided - Added edge-case tests covering empty threshold iterables, mixed-
Nonethreshold groups in dict mode, and all-Noneboth-groups behavior - Updated
CHANGELOG.mdwith entries for both the fix and the new tests
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
balance/stats_and_plots/weights_stats.py |
Introduces PropAboveBelowResult TypedDict, adds @overload signatures, and replaces unsafe pd.concat with filtered-pieces guard |
tests/test_stats_and_plots.py |
Adds test_prop_above_and_below_edge_cases covering empty iterables, mixed-None dict mode, and both-None case |
CHANGELOG.md |
Records the return-path stabilization and expanded test coverage |
Two issues were identified:
-
Second
@overloadhas an unnecessary and misleading default value (line 222):return_as_series: Literal[False] = FalsedeclaresFalseas the default, creating ambiguity for Pyre/mypy when the argument is omitted — both overloads now claim to apply. The standard pattern is to omit the default on the non-default overload:return_as_series: Literal[False](no= False). -
Docstring
Returnssection andbelow/aboveparameter descriptions are stale (lines 227–232 area): TheReturns:type hint still sayspd.Series | dictinstead ofpd.Series | PropAboveBelowResult | None, and the descriptions forbelowandabovestill say "Using None returns None," which is only true when both areNone.
|
@talgalili has imported this pull request. If you are a Meta employee, you can view this in D95019739. |
|
@talgalili merged this pull request in ddae91c. |
No description provided.