fix: support 0D MeanView/WeightedMeanView#1100
Merged
Conversation
Agent-Logs-Url: https://github.com/scikit-hep/boost-histogram/sessions/82d01cbe-1727-488e-ac89-cb5d92015da1 Co-authored-by: henryiii <4616906+henryiii@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix issue retrieving mean from 0D profile
Fix TypeError when accessing fields of a 0-d MeanView/WeightedMeanView
Mar 27, 2026
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.
Projecting all axes from a profile histogram yields a 0-d histogram, but accessing
.values(),.variances(),.counts(), or any named field on the resulting view raisedTypeError: iteration over a 0-d array.Root cause
In
View.__getitem__, when a named field is accessed on a 0-d structured array (e.g.view["value"]), numpy returns a 0-d non-structured float array. The old code hitif not sliced.shapefirst and tried_PARENT._make(*sliced)— unpacking a 0-d array — before it could reach the dtype-changed guard.Changes
src/boost_histogram/view.py— swap check order inView.__getitem__: testsliced.dtype != self.dtype(field access) beforenot sliced.shape(scalar structured element). The shape check still correctly handles 0-d numpy void scalars produced by integer indexing on a 1-d view.tests/test_views.py— addtest_0d_mean_viewandtest_0d_weighted_mean_viewcovering.values(),.variances(),.counts(), and direct field access on 0-d profiles.📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.