Fix serialization round-trip for 3D histograms with empty axes#1094
Draft
Fix serialization round-trip for 3D histograms with empty axes#1094
Conversation
Co-authored-by: henryiii <[email protected]>
Copilot
AI
changed the title
[WIP] Fix serialization issue for 3D histograms
Fix serialization round-trip for 3D histograms with empty axes
Mar 20, 2026
Member
|
I kind of told it to just start with the test, but I guess the fix is welcome too... I love that it did a variety of storages, and handles the special case. :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JSON serialization collapses empty numpy dimensions — a
(5, 0, 0)array becomes[[], [], [], [], []]and deserializes as(5, 0), causingfrom_uhito assign data with the wrong number of dimensions into the reconstructed histogram.Changes
src/boost_histogram/serialization/__init__.py: Infrom_uhi, reshape the raw storage data to the correct shape derived from the histogram's view after reconstruction:int,double): reshape toview_shapeweighted,mean,weighted_mean): reshape toview_shape + (accumulator_dim,)This is a no-op for non-empty histograms and restores lost dimensions for empty ones.
tests/test_serialization_uhi.py: Adds regression tests simulating a JSON round-trip (the mechanism that triggers dimension collapse) across all 5 storage types, plus a test reproducing the exact constructor path from the bug report.Original prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.