Skip to content

feat: support axes growth in serialization#1074

Merged
henryiii merged 2 commits intodevelopfrom
henryiii/feat/axesgrowth
Jan 28, 2026
Merged

feat: support axes growth in serialization#1074
henryiii merged 2 commits intodevelopfrom
henryiii/feat/axesgrowth

Conversation

@henryiii
Copy link
Copy Markdown
Member

Record growth=True in serialization, and respect it if present.

Close #1073.

Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
@github-actions github-actions bot added the needs changelog Might need a changelog entry label Jan 28, 2026
@henryiii henryiii requested a review from Copilot January 28, 2026 04:22
Copy link
Copy Markdown
Contributor

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 pull request adds support for preserving the growth trait of axes during serialization and deserialization, addressing issue #1073. Previously, when a histogram with growable axes was serialized and then deserialized, the growth trait was lost, which prevented the deserialized histogram from growing its axes during fills.

Changes:

  • Added serialization logic to record growth=True in the writer_info section when an axis has the growth trait enabled
  • Added deserialization logic to read and respect the growth flag from writer_info when reconstructing axes
  • Added tests to verify growth trait preservation in round-trip serialization

Reviewed changes

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

File Description
src/boost_histogram/serialization/_axis.py Modified serialization functions to write growth trait to writer_info for all axis types that support growth (Regular, Integer, Variable, IntCategory, StrCategory), and modified deserialization to read and apply the growth parameter when constructing axes
tests/test_serialization_uhi.py Added test for Integer axis with growth=True to verify round-trip preservation, and added assertion to existing test to verify growth trait is preserved

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +222 to +233
def test_round_trip_growth() -> None:
h = bh.Histogram(
bh.axis.Integer(0, 10, growth=True),
)
h.fill([-1, 0, 0, 1, 20, 20, 20])
data = to_uhi(h)
h2 = from_uhi(data)

assert h == h2

assert isinstance(h2.axes[0], bh.axis.Integer)
assert h2.axes[0].traits.growth == h.axes[0].traits.growth
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The test only covers Integer axes with growth. Consider adding tests for other axis types that support growth to ensure comprehensive coverage. Specifically, Regular, Variable, IntCategory, and StrCategory axes all support the growth trait and have serialization code added for it in this PR. Testing these would verify that the serialization/deserialization works correctly for all axis types that support growth.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I knew that when writing it, I was just lazy. I am going to continue to be lazy and let AI write the expanded tests for me so I can focus on stuff that's more fun. :)

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 28, 2026

@henryiii I've opened a new pull request, #1076, to work on those changes. Once the pull request is ready, I'll request review from you.

* Initial plan

* test: expand growth serialization test to cover all axis types

Co-authored-by: henryiii <4616906+henryiii@users.noreply.github.com>

* style: pre-commit fixes

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: henryiii <4616906+henryiii@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@henryiii henryiii merged commit f18f710 into develop Jan 28, 2026
20 checks passed
@henryiii henryiii deleted the henryiii/feat/axesgrowth branch January 28, 2026 15:51
@henryiii henryiii removed the needs changelog Might need a changelog entry label Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Axis trait growth isn't preserved in serialization roundtrips

3 participants