Skip to content

Comments

add from_underlying and get_underlying methods#38

Open
niklebedenko wants to merge 1 commit intodavehadley:developfrom
niklebedenko:develop
Open

add from_underlying and get_underlying methods#38
niklebedenko wants to merge 1 commit intodavehadley:developfrom
niklebedenko:develop

Conversation

@niklebedenko
Copy link

Hi there, I'm loving this crate -- there was just one little thing that I really needed: a constructor & getter for the underlying data. I needed this so that I could implement rkyv traits for your types. The alternative would be to add rkyv as a dependency to your crate (behind a feature flag) and add its #[derive] macros everywhere. Instead, I thought that adding a couple extra methods would hopefully mean that nobody else needs to add their own favourite macros.

@codecov
Copy link

codecov bot commented Jun 30, 2025

Codecov Report

Attention: Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.

Project coverage is 90.45%. Comparing base (8c0f235) to head (56c3fb2).

Files with missing lines Patch % Lines
ndhistogram/src/histogram/vechistogram.rs 0.00% 9 Missing ⚠️
ndhistogram/src/histogram/hashhistogram.rs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #38      +/-   ##
===========================================
- Coverage    91.82%   90.45%   -1.37%     
===========================================
  Files           20       20              
  Lines         1125     1079      -46     
===========================================
- Hits          1033      976      -57     
- Misses          92      103      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Owner

@davehadley davehadley left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, @niklebedenko.

There are many missing methods that it would be useful to add to these structs. In principle I have no objection to adding these. I attached some inline comments with the code.

I don't like the nomenclature of *_underlying. Looking around for an analogy in the Rust standard library we have String::from_utf8 and String::as_bytes.
So perhaps, from_vec / from_map and as_vec / as_map would be better names?


/// Constructs a new histogram from the underlying data
pub fn from_underlying(axes: A, values: HashMap<usize, V>) -> Self {
Self { axes, values }
Copy link
Owner

Choose a reason for hiding this comment

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

How should this behave if values contains an entry for usize that does not correspond to a valid bin index in the provided axes?


/// Returns `None` if the number of values does not match the
/// expected number of bins for the given axes.
pub fn from_underlying(axes: A, values: Vec<V>) -> Option<Self> {
Copy link
Owner

Choose a reason for hiding this comment

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

I think that it would be better if this returned a Result rather than an Option. There is already a AxisError::InvalidNumberOfBins that might be an appropriate thing to return here.

@davehadley
Copy link
Owner

@niklebedenko is this pull request still in active development?

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.

2 participants