Skip to main content

Balance in motion - v0.12.0 expands Python version support, visualizations, and statistical methods

· 4 min read

tl;dr – balance v0.12.0

We're excited to announce balance v0.12.0! Since our initial release, balance has evolved into a comprehensive Python package for adjusting biased samples. This post highlights the most significant improvements from v0.1.0 (2022-11-20) through v0.12.0 (2025-10-14), showcasing how we've made balance easier to use:

  • Expanded compatibility: Now supports Python 3.9–3.14 on Windows, macOS, and Linux, with smarter dependency management and a switch to the MIT license.
  • Major upgrades: Improved statistical methods (IPW, raking, poststratification), interactive Plotly visualizations, and new variance/confidence interval tools.
  • Better experience: Enhanced CLI, bug fixes, and expanded docs/tutorials for easier use and learning.

balance_logo_horizontal

Cutting-Edge Python Compatibility

balance now supports all three major OS platforms: Windows, macOS, and Linux - for Python 3.9 through 3.14, ensuring you can use the latest Python features without compatibility concerns.

What's New:

  • Full support for Windows
  • Full support for Python 3.11, 3.12, 3.13 and 3.14
  • Smart dependency management with version-specific constraints for numpy, pandas, scipy, and scikit-learn for Python 3.9-3.11.
  • Greater flexibility for Python 3.12+ users with removed upper version constraints, while eliminating 260+ pandas deprecation warnings and modernized our code.
  • Python 3.8 deprecated due to typing incompatibilities
  • License Update from GPL v2 to the MIT license for greater flexibility and easier integration into your projects

Methodological Improvements

Transition to scikit-learn for IPW

We've migrated from glmnet to scikit-learn's logistic regression (v0.10.0) for our inverse propensity weighting (IPW) method, bringing significant benefits:

Pros:

  • Windows OS support
  • Python 3.11+ compatibility
  • Eliminated glmnet dependency

Trade-offs:

  • Uses L2 penalties instead of L1 (slight weight differences)
  • 2-5x slower than previous version

Raking Algorithm: Faster and More Reliable

We've completely refactored our raking (rake weighting) implementation with an array-based IPFN algorithm that delivers:

  • Support for marginal distribution target distributions with the new prepare_marginal_dist_for_raking helper function
  • Better performance across all Python versions
  • Consistent results through automatic variable alphabetization

Flexibility with Poststratification

The poststratify method now includes a strict_matching parameter (default True). When set to False, it gracefully handles missing sample cells by issuing warnings and assigning zero weights.

Visualization and Summarization Enhancements

Interactive Plotting

All visualization functions now produce interactive Plotly plots by default:

  • Customizable layouts via kwargs (control width, height, and more)
  • New plotly_plot_density for interactive kernel density estimation with support for 'kde' plots in plotly_plot_dist and plot_dist
  • BalanceWeightsDF.plot now uses Plotly instead of static seaborn plots

All bar plots now support ylim argument for precise y-axis control: s3_null.covars().plot(ylim=(0, 1))

Statistical Summaries

New variance and confidence interval methods make it easier to assess uncertainty:

  • .var_of_mean() - Variance of weighted means
  • .ci_of_mean() - Confidence intervals for weighted means
  • .mean_with_ci() - Combined mean with confidence intervals
  • Enhanced .summary() method for BalanceWeightsDF

Developer Experience

Notable Bug Fixes

  • Fixed rm_mutual_nas to preserve Series index
  • Improved Sample.from_frame weight column detection (now recognizes "weights" and "weight")
  • Better handling of int8/int16 columns (converts to float16)
  • Fixed color assignments in comparison plots
  • Resolved various edge cases in plot_hist_kde and plot_bar

CLI Improvements

The command-line interface now offers more control:

  • Formula specification via string arguments
  • Type standardization controls
  • Original dtype preservation with --return_df_with_original_dtypes
  • Flexible trimming with weight_trimming_mean_ratio=None option
  • Enhanced logging with dtype change warnings

Documentation & Tutorials

We've significantly expanded our documentation with new tutorials:

Also added a Link to conference presentations (ISA 2023).

This extends our existing Statistical Methods Documentation:

Community & Contributors

A huge thank you to our contributors: @talgalili, @wesleytlee, @SarigT, @ahakso, @stevemandala, @tomwagstaff-opml, @zbraiterman, and @luca-martial!

Want to contribute? Check out our contributing guide.


Get Started Today

Ready to try balance or upgrade to v0.12.0?

Installation:

python -m pip install balance

Resources:

Get Help:

We welcome your feedback, questions, and contributions as we continue making balance the go-to tool for survey statistics and bias adjustment in Python!