Open bemoody opened 2 months ago
I don't understand the "subclasses of ndarray" comment
The commit message gives slightly more explanation
commit 9c7e6e30315ab4541775d9a78630e88423c752c1
Author: Charles Harris <charlesr.harris@gmail.com>
Date: Fri Oct 4 13:49:33 2013 -0600
BUG: Refactor nanfunctions to behave as agreed on for 1.9.
Deal with subclasses of ndarray, like pandas.Series and matrix.
Subclasses may not define the new keyword keepdims or deal
gracefully with ufuncs in all their forms. This is solved by
throwing the problem onto the np.sum, np.any, etc. functions
that have ugly hacks to deal with the problem.
Settle handling of all-nan slices.
nanmax, nanmin -- Raise warning, return NaN for slice.
nanargmax, nanargmin -- Raise ValueError.
nansum -- Return 0 for slice.
nanmean, nanvar, nanstd -- Raise warning, return NaN for slice.
Make NaN functions work for scalar arguments.
This may seem silly, but it removes a check for special cases.
Update tests
Deal with new all-nan handling.
Test with matrix class as example of subclass without keepdims.
Test with scalar arguments.
Fix nanvar issue reported in #3860.
Closes #3860 #3850
Indeed, I see that pandas.Series chokes with keepdims=True. But we're not doing that so I think we should be fine with np.fmin.reduce(self.p_signal, axis=0)
.
If we care about object arrays, we could use np.nanargmin
and np.nanargmax
instead (but those are less efficient for numeric arrays.)
If all samples in a channel are NaN,
calc_adc_params
will fail:A couple things are wrong here:
if pmin == np.nan
doesn't do what you think.nanmin
andnanmax
will give a RuntimeWarning if all samples in a channel are NaN.(1) is easy to fix. (2) is a little weirder; have a look at the code of nanmin:
In other words, for ordinary numeric numpy arrays,
np.fmin.reduce
gives what we want (minimum non-NaN value if there is one, otherwise NaN, and no warning.) It might not work if the array is something more exotic (e.g. a numpy-compatible array class created by some other python package.)I think I understand the comment about object arrays (https://github.com/numpy/numpy/issues/8975, https://github.com/numpy/numpy/issues/9009), but I don't understand the "subclasses of ndarray" comment. When I try creating a trivial subclass of ndarray, fmin still appears to work as expected. So I don't see why the strict
is np.ndarray
is needed.