Skip to content

Refactor _auto_bar_width and add _auto_bar_width_columnar#348

Closed
talgalili wants to merge 2 commits intofacebookresearch:mainfrom
talgalili:export-D94465988
Closed

Refactor _auto_bar_width and add _auto_bar_width_columnar#348
talgalili wants to merge 2 commits intofacebookresearch:mainfrom
talgalili:export-D94465988

Conversation

@talgalili
Copy link
Contributor

Summary:
Refactored the _auto_bar_width function to simplify its interface by removing the unused n_datasets parameter, and extracted the columnar layout logic into a new dedicated _auto_bar_width_columnar function.

The original _auto_bar_width was trying to serve two different purposes but the n_datasets parameter wasn't actually used in the calculation. This change:

  • Simplifies _auto_bar_width for single-bar-per-line layouts (grouped barplots and histograms)
  • Adds _auto_bar_width_columnar specifically for side-by-side columnar layouts used by ascii_comparative_hist
  • Improves code clarity by having separate functions with clear docstrings for each use case
  • Removed Overriding n_bins and bar_width example from balance_ascii_plots.ipynb

Reviewed By: talgalili

Differential Revision: D94465988

Summary:
Refactored the `_auto_bar_width` function to simplify its interface by removing the unused `n_datasets` parameter, and extracted the columnar layout logic into a new dedicated `_auto_bar_width_columnar` function.

The original `_auto_bar_width` was trying to serve two different purposes but the `n_datasets` parameter wasn't actually used in the calculation. This change:
- Simplifies `_auto_bar_width` for single-bar-per-line layouts (grouped barplots and histograms)
- Adds `_auto_bar_width_columnar` specifically for side-by-side columnar layouts used by `ascii_comparative_hist`
- Improves code clarity by having separate functions with clear docstrings for each use case
- Removed Overriding n_bins and bar_width example from balance_ascii_plots.ipynb

Reviewed By: talgalili

Differential Revision: D94465988
Copilot AI review requested due to automatic review settings February 26, 2026 07:25
@meta-cla meta-cla bot added the cla signed label Feb 26, 2026
@meta-codesync
Copy link

meta-codesync bot commented Feb 26, 2026

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

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 refactors the ASCII plotting functions to better separate concerns and simplify the bar width calculation logic. The main goal is to distinguish between single-bar-per-line layouts (grouped barplots and histograms) and columnar side-by-side layouts (comparative histograms).

Changes:

  • Simplified _auto_bar_width by removing the unused n_datasets parameter
  • Added dedicated _auto_bar_width_columnar function for columnar layouts with proper space accounting for multiple columns
  • Changed ascii_plot_dist to use ascii_comparative_hist for numeric variables instead of ascii_plot_hist, resulting in a different output format (columnar vs. multi-line)

Reviewed changes

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

File Description
balance/stats_and_plots/ascii_plots.py Refactored _auto_bar_width to remove unused parameter, added _auto_bar_width_columnar for columnar layouts, updated ascii_plot_dist to use ascii_comparative_hist, updated docstrings and examples
tests/test_ascii_plots.py Updated tests to call _auto_bar_width with one parameter, added tests for _auto_bar_width_columnar, updated expected outputs to match new comparative histogram format
tutorials/balance_ascii_plots.ipynb Removed section 6 about overriding n_bins and bar_width parameters, consolidated tutorial introduction
Comments suppressed due to low confidence (1)

balance/stats_and_plots/ascii_plots.py:786

  • This is a breaking change in the output format for numeric variables in ascii_plot_dist. Previously it used ascii_plot_hist which shows each dataset on a separate line within each bin. Now it uses ascii_comparative_hist which shows all datasets as columns on the same line. According to the coding guidelines (review checklist item 5), breaking changes must be explicitly labeled in the CHANGELOG with migration notes and before/after examples. This change should be documented in the CHANGELOG.md file under "Breaking Changes".
                ascii_comparative_hist(

@meta-codesync
Copy link

meta-codesync bot commented Feb 26, 2026

@sahil350 has imported this pull request. If you are a Meta employee, you can view this in D94465988.

meta-codesync bot pushed a commit that referenced this pull request Feb 26, 2026
Summary:
Refactored the `_auto_bar_width` function to simplify its interface by removing the unused `n_datasets` parameter, and extracted the columnar layout logic into a new dedicated `_auto_bar_width_columnar` function.

The original `_auto_bar_width` was trying to serve two different purposes but the `n_datasets` parameter wasn't actually used in the calculation. This change:
- Simplifies `_auto_bar_width` for single-bar-per-line layouts (grouped barplots and histograms)
- Adds `_auto_bar_width_columnar` specifically for side-by-side columnar layouts used by `ascii_comparative_hist`
- Improves code clarity by having separate functions with clear docstrings for each use case
- Removed Overriding n_bins and bar_width example from balance_ascii_plots.ipynb

Differential Revision: D94465988

Pulled By: sahil350

fbshipit-source-id: fad39e4a7ebbf90dbc9e3c9d2df28672147c7145
@neuralsorcerer
Copy link
Collaborator

Closing this PR since the changes have already been committed.

@talgalili
Copy link
Contributor Author

Thanks @neuralsorcerer

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.

4 participants