Skip to content

Update user-facing functions docstring with examples (#258)#259

Closed
talgalili wants to merge 1 commit intofacebookresearch:mainfrom
talgalili:export-D90492354
Closed

Update user-facing functions docstring with examples (#258)#259
talgalili wants to merge 1 commit intofacebookresearch:mainfrom
talgalili:export-D90492354

Conversation

@talgalili
Copy link
Contributor

Summary:

Differential Revision: D90492354

Pulled By: talgalili

Copilot AI review requested due to automatic review settings January 12, 2026 11:56
@meta-cla meta-cla bot added the cla signed label Jan 12, 2026
@meta-codesync
Copy link

meta-codesync bot commented Jan 12, 2026

@talgalili has exported this pull request. If you are a Meta employee, you can view the originating Diff in D90492354.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds concrete usage examples to docstrings for user-facing functions across the balance package to improve documentation and help developers understand how to use the APIs. The PR also updates formatting from :: to .. code-block:: python for consistency and includes workflow file changes.

Changes:

  • Added docstring examples with expected outputs to 40+ user-facing functions across weighting methods (rake, ipw, cbps, adjust_null), statistics utilities (weighted_stats, weighted_comparisons_stats, general_stats), and core classes (Sample, BalanceDF)
  • Updated reStructuredText formatting from :: to .. code-block:: python for consistency across existing examples
  • Updated GitHub Actions workflow to use Python 3.12 and black 25.1.0 for linting

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
balance/weighting_methods/rake.py Added example for rake() and updated formatting for helper functions (_proportional_array_from_dict, _find_lcm_of_array_lengths, _realize_dicts_of_proportions, prepare_marginal_dist_for_raking)
balance/weighting_methods/ipw.py Added examples for model_coefs(), link_transform(), calc_dev(), weights_from_link(), and choose_regularization()
balance/weighting_methods/cbps.py Added examples for logit_truncated(), compute_pseudo_weights_from_logit_probs(), bal_loss(), gmm_function(), gmm_loss(), alpha_function(), compute_deff_from_beta(), and cbps()
balance/weighting_methods/adjust_null.py Added example for adjust_null()
balance/stats_and_plots/weighted_stats.py Updated formatting and added examples for weighted_var(), weighted_sd(), and weighted_quantile()
balance/stats_and_plots/weighted_comparisons_stats.py Updated formatting and added examples for asmd_improvement() and outcome_variance_ratio()
balance/stats_and_plots/general_stats.py Rewrote example for relative_response_rates() with simpler, clearer demonstration
balance/sample_class.py Added examples for 20+ methods including from_frame(), df, outcomes(), weights(), covars(), ignored_columns(), model(), model_matrix(), set_weights(), set_unadjusted(), is_adjusted(), set_target(), has_target(), design_effect(), design_effect_prop(), outcome_sd_prop(), outcome_variance_ratio(), summary(), diagnostics(), keep_only_some_rows_columns(), to_download(), to_csv(), and updated formatting for others
balance/csv_utils.py Added example for to_csv_with_defaults()
balance/balancedf_class.py Updated formatting and added examples for to_download(), df, summary(), from_frame(), design_effect(), trim(), and to_csv()
balance/adjustment.py Updated example for trim_weights() to be more concise and added example for default_transformations()
CHANGELOG.md Added entry documenting synchronization of docstring examples with test cases
.github/workflows/build-and-test.yml Updated Python version from 3.9 to 3.12 and black version from 24.4.2 to 25.1.0 for linting job

- name: Install dependencies
run: |
pip install flake8 black==24.4.2 ruff-api==0.1.0 ufmt==2.8.0 usort==1.0.8.post1
pip install flake8 black==25.1.0 ruff-api==0.1.0 ufmt==2.8.0 usort==1.0.8.post1
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The black version is updated to 25.1.0 in the workflow file, but requirements-fmt.txt still specifies black==24.4.2. This creates an inconsistency where the CI linting job and local development would use different black versions, potentially causing formatting discrepancies. Either both should be updated together, or this change should be in a separate PR focused on dependency updates.

Suggested change
pip install flake8 black==25.1.0 ruff-api==0.1.0 ufmt==2.8.0 usort==1.0.8.post1
pip install flake8 black==24.4.2 ruff-api==0.1.0 ufmt==2.8.0 usort==1.0.8.post1

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +50
python-version: 3.12
- name: Install dependencies
run: |
pip install flake8 black==24.4.2 ruff-api==0.1.0 ufmt==2.8.0 usort==1.0.8.post1
pip install flake8 black==25.1.0 ruff-api==0.1.0 ufmt==2.8.0 usort==1.0.8.post1
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow file changes (updating Python version from 3.9 to 3.12 for linting and updating black version from 24.4.2 to 25.1.0) are unrelated to adding docstring examples. According to the project's coding guidelines, each PR should represent one self-contained idea. These infrastructure changes should be in a separate PR to maintain clear change history and easier review/rollback if needed.

Copilot generated this review using guidance from repository custom instructions.
talgalili added a commit to talgalili/balance that referenced this pull request Jan 12, 2026
…research#259)

Summary:

**User-facing docstring improvements:**
- Resolves facebookresearch#192
- Added comprehensive examples to user-facing function docstrings
- Will update missing ones (if any) in a separate PR

**Formatting toolchain upgrade to Black 25.1.0:**
- Syncs with Meta's internal tooling (D90476287)
- Switched ufmt formatter from `ruff-api` to `black`
- Updated Black 24.4.2 → 25.1.0 in CI workflow, pre-commit config, and requirements
- Added Python 3.14 to Black's `target-version` for forward compatibility
- Removed unnecessary `ruff-api` dependency

Differential Revision: D90492354
Copilot AI review requested due to automatic review settings January 12, 2026 12:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.

talgalili added a commit to talgalili/balance that referenced this pull request Jan 12, 2026
…research#259)

Summary:

**User-facing docstring improvements:**
- Resolves facebookresearch#192
- Added comprehensive examples to user-facing function docstrings
- Will update missing ones (if any) in a separate PR

**Formatting toolchain upgrade to Black 25.1.0:**
- Syncs with Meta's internal tooling (D90476287)
- Switched ufmt formatter from `ruff-api` to `black`
- Updated Black 24.4.2 → 25.1.0 in CI workflow, pre-commit config, and requirements
- Added Python 3.14 to Black's `target-version` for forward compatibility
- Removed unnecessary `ruff-api` dependency

Differential Revision: D90492354
Copilot AI review requested due to automatic review settings January 12, 2026 13:01
talgalili added a commit to talgalili/balance that referenced this pull request Jan 12, 2026
…esearch#259)

Summary:

**User-facing docstring improvements:**
- Resolves facebookresearch#192
- Added comprehensive examples to user-facing function docstrings
- Will update missing ones (if any) in a separate PR

**Aligned formatting toolchain with Meta's internal `pyfmt` configuration:**
- Switched ufmt formatter from `black` to `ruff-api` to match Meta's internal `tools/lint/pyfmt/config.toml` defaults for `fbcode/`.
- This eliminates formatting drift between internal and external CI, ensuring files formatted internally pass GitHub Actions checks.
- Updated CI workflow, pre-commit config, and `requirements-fmt.txt` to use `ruff>=0.4.0` instead of Black.
- Added `[tool.ruff]` and `[tool.ruff.format]` configuration to `pyproject.toml` for consistent formatting behavior.

Differential Revision: D90492354
talgalili added a commit to talgalili/balance that referenced this pull request Jan 12, 2026
…esearch#259)

Summary:

**User-facing docstring improvements:**
- Resolves facebookresearch#192
- Added comprehensive examples to user-facing function docstrings
- Will update missing ones (if any) in a separate PR

**Aligned formatting toolchain with Meta's internal `pyfmt` configuration:**
- Switched ufmt formatter from `black` to `ruff-api` to match Meta's internal `tools/lint/pyfmt/config.toml` defaults for `fbcode/`.
- This eliminates formatting drift between internal and external CI, ensuring files formatted internally pass GitHub Actions checks.
- Updated CI workflow, pre-commit config, and `requirements-fmt.txt` to use `ruff>=0.4.0` instead of Black.
- Added `[tool.ruff]` and `[tool.ruff.format]` configuration to `pyproject.toml` for consistent formatting behavior.

Differential Revision: D90492354
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Comment on lines 1 to 5
# Generated from Meta's internal pyfmt requirements
# Keep these versions in sync with Meta's internal
# tools/lint/pyfmt/reqs/requirements-fmt.txt
black==24.4.2
ruff-api==0.1.0
stdlibs==2024.1.28
# tools/lint/pyfmt configuration
ruff>=0.4.0
ufmt==2.8.0
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR combines two distinct concerns: (1) adding docstring examples to user-facing functions, and (2) migrating the formatting toolchain from black/usort to ruff. According to best practices for this repository, each PR should represent one self-contained idea. Consider splitting this into two PRs: one for the formatting toolchain migration (requirements-fmt.txt, pyproject.toml, .pre-commit-config.yaml, .github/workflows/build-and-test.yml) and another for the docstring example additions (all the .py files). This would make each change easier to review, test, and potentially revert if needed.

Copilot generated this review using guidance from repository custom instructions.
…esearch#259)

Summary:

**User-facing docstring improvements:**
- Resolves facebookresearch#192
- Added comprehensive examples to user-facing function docstrings
- Will update missing ones (if any) in a separate PR

**Aligned formatting toolchain with Meta's internal `pyfmt` configuration:**
- Switched ufmt formatter from `black` to `ruff-api` to match Meta's internal `tools/lint/pyfmt/config.toml` defaults for `fbcode/`.
- This eliminates formatting drift between internal and external CI, ensuring files formatted internally pass GitHub Actions checks.
- Updated CI workflow, pre-commit config, and `requirements-fmt.txt` to use `ruff>=0.4.0` instead of Black.
- Added `[tool.ruff]` and `[tool.ruff.format]` configuration to `pyproject.toml` for consistent formatting behavior.

Differential Revision: D90492354
@meta-codesync
Copy link

meta-codesync bot commented Jan 12, 2026

This pull request has been merged in c8519a2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Update the dosctring of all user-facing functions with 'examples' from the tests

3 participants