Skip to content

Comments

fix: correct repr for MultiCell#1087

Merged
henryiii merged 2 commits intodevelopfrom
henryiii/fix/multicell_nelem
Feb 4, 2026
Merged

fix: correct repr for MultiCell#1087
henryiii merged 2 commits intodevelopfrom
henryiii/fix/multicell_nelem

Conversation

@henryiii
Copy link
Member

@henryiii henryiii commented Feb 3, 2026

Followup to #1008. This fixes the repr for MultiCell, which currently always shows 0, since we can't get the actual instance, but just it's type (without the value of nelem).

I've added a h.get_storage() method which gets a storage object with the same parameters, an instance of h.storage_type. It's natural for the repr, and allows users to query with h.get_storage().nelem. Thoughts, @HDembinski and @Superharz? I could make it a property instead, such as h.storage.nelem. The main issue is it is just the bh.storage creation object, and doesn't actually give access to storage, so you can't do much with h.storage.

Edit: I realized that making this a property actually works better for pattern matching, which expects properties to match constructor arguments, so I've used h.storage now.

I thought about exposing .nelem on the histogram, but I can't properly statically type it (mypy doesn't allow @property and @typing.overload to be combined), and it's just None on most histograms.

Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
@github-actions github-actions bot added the needs changelog Might need a changelog entry label Feb 3, 2026
@henryiii henryiii force-pushed the henryiii/fix/multicell_nelem branch 2 times, most recently from 9f3b02d to 4dc8d93 Compare February 4, 2026 01:45
@Superharz
Copy link
Contributor

Hi @henryiii, I am definitely in favor of having the correct number of cells contained in the representation. I also noticed that right now it always says MultiCell(0) regardless of the specific number of cells.

@HDembinski
Copy link
Member

Lgtm

Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
@henryiii henryiii force-pushed the henryiii/fix/multicell_nelem branch from 4dc8d93 to 2cf4174 Compare February 4, 2026 19:50
@henryiii henryiii merged commit bb45380 into develop Feb 4, 2026
20 checks passed
@henryiii henryiii deleted the henryiii/fix/multicell_nelem branch February 4, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs changelog Might need a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants