Breaking Changes
-
id_columnnow returns the column name (str) onSampleFrame,
BalanceFrame, andSample. Previously it returned ID data
(pd.Series), which was inconsistent withweight_column(which returned
a name after 0.19.0). Useid_seriesfor ID data,weight_seriesfor
weight data. The accessor naming convention is now consistent:*_column→ column name (str):id_column,weight_column*_series→ column data (pd.Series):id_series,weight_seriesdf_*→ DataFrame:df_covars,df_weights,df_outcomes
Both
id_columnandweight_columnemitFutureWarnings pointing at the
new data-returning accessors; warnings will be removed after 2026-06-01.
TheBalanceDFSourceprotocol was updated accordingly (id_column→
id_series); custom implementations must rename this property. -
Unknown kwargs to
poststratify(...)now raiseTypeErrorinstead of
being silently ignored, to catch typos.store_fit_metadatamust be a
boolean.
New Features
-
Added sklearn-style
fit/predict_weightsworkflow onBalanceFrame- New entry points
BalanceFrame.fit(...),design_matrix(on=..., data=...),
predict_proba(on=..., output=..., data=...), andpredict_weights(data=...)
enable training a weighting model on one BalanceFrame and applying it to new
data viadata=...for one-liner holdout scoring
(fitted.predict_weights(data=holdout_bf)). - Supports IPW, CBPS, and poststratify methods. Each stores the fit-time
metadata needed to reconstruct weights (training design weights, trimming
options, CBPS coefficients, poststratify cell-ratio tables, NA handling). BalanceFrame.set_fitted_model(fitted)applies a fitted model from one
BalanceFrame to another for holdout scoring workflows.
- New entry points
-
Added formula support in
poststratifypoststratify(...)andBalanceFrame.adjust(method="poststratify", ...)
now acceptformula=(string or list) as an alternative tovariables=.- Only interaction-style operators are supported:
:(interaction),
.(all common columns),-(exclude), and optional leading~.
Additive+and*are explicitly rejected because post-stratification
defines cells by the joint distribution —a + b,a * b, anda:b
would all produce identical cells, and rejecting+/*prevents users
from silently writing what looks like a main-effects model. - Strict formula validation: empty/non-string entries, unknown variables,
transformed terms, and passing bothvariablesandformulaall raise
explicitValueError. Note: raking operates on marginals, so+/*
will be meaningful when raking gains its ownformula=argument.
-
Added
BalanceFrame.set_as_pre_adjust()to lock in the current
responder state as the new pre-adjust baseline. Supportsinplace=False
(default, immutable) andinplace=True. Clears the adjustment model and
unadjusted link since the object is no longer considered adjusted.
Code Quality & Refactoring
-
Safer target replacement on adjusted objects —
BalanceFrame.set_target(...)
now warns when replacing the target on an adjusted object in-place, since
this resets responder weights to pre-adjust values and drops the current
adjustment result. -
Modernized weight dtype checks for pandas 3.0 compatibility —
SampleFrame.set_weights()paths now use explicit exact-float64checks
instead of deprecated float-dtype helpers, and always coerce assigned
weights to exactfloat64. -
Cleaned up legacy Python 2
__future__compatibility imports in
weighting methods — replaced obsolete imports with
from __future__ import annotationsinadjust_null,cbps,
poststratify, andrake. Note: with this future import enabled,
runtime annotation introspection changes (__annotations__become
postponed/stringized).
Tests
- Added coverage for the new fit/predict_weights workflow (IPW, CBPS,
poststratify), pickle/deepcopy roundtrips of fitted BalanceFrames,
raw-covariate fit-matrix persistence (use_model_matrix=False),
near-separation stability, empty-input validation, formula parsing edge
cases (interaction syntax, dot expansion, explicit~formulas,
validation failures),set_as_pre_adjust()behavior (copy / in-place /
inherited-view sync), target-replacement warning emission, weight-column
casting when active weight dtype is non-float/float32, and chained
IPW→poststratify adjustment behavior.
Contributors
@talgalili, @sahil350 ,@neuralsorcerer