-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace min/max, make quantile_mut return None for empty arrays, and fix docs #13
Conversation
The problem with the old methods was that they panicked when the array was empty, which was very problematic. (See rust-ndarray/ndarray#512 for discussion.) The old `min_partialord` and `max_partialord` have been renamed to `min`/`max`.
I'll review it tomorrow morning. On histogram's panics: should we change the signature to return a
Returning a Result would probably give a chance to the user to specify a default that makes sense to them, especially if we provide a useful error. |
For empty arrays, I think the right thing to do is to have For constant arrays, I think the right thing to do is have For Freedman Diaconis with IQR=0, I'm not sure; that requires some thought. Panicking definitely isn't the right thing, because IMO panics shouldn't be a function of the data in the array. I think I'd return an By the way, in a future version, I'm thinking about replacing impl<A: Ord> Grid<A> {
fn fit_array<S, B>(array: &ArrayBase<S, Ix2>, strategy: &B) -> Result<Self, Error>
where
S: Data<Elem = A>,
B: BinsBuildingStrategy<A>,
{
// ...
}
}
pub trait BinsBuildingStrategy<A: Ord> {
fn fit_array<S>(&self, array: &ArrayBase<S, Ix1>) -> Result<Bins<A>, Error>
where
S: Data<Elem = A>;
} The |
It makes sense, I agree.
We could use a "default" width of 1, that could be the way. I'd avoid duplicate edges since they would still lead to empty bins and a degenerate grid (no observation would be captured), thus surprising the user.
A |
This PR does a few things:
min
/max
methods with the oldmin_partialord
/max_partialord
. (Renamemin_partialord
/max_partialord
tomin
/max
.) See this comment for more explanation. The primary issue with the oldmin
/max
methods is that they panicked on empty arrays.quantile_mut
returnNone
for empty arrays. It's easy to forget about the possibility of empty arrays, so it's important to remind the user of the possibility and force them to handle it. See this comment for more justification.quantile_mut
.Edit: I'm uncomfortable with the histogram strategies panicking in so many cases, but we can fix that in a later version.