Equivalent to arr1d[~arr1d.isnan()], but in a different order Presumably faster as it incurs fewer copies Parameters ---------- arr1d : ndarray Array to remove nans from overwrite_input : bool True if `arr1d` can be modified in place Returns ------
(arr1d, overwrite_input=False)
| 140 | |
| 141 | |
| 142 | def _remove_nan_1d(arr1d, overwrite_input=False): |
| 143 | """ |
| 144 | Equivalent to arr1d[~arr1d.isnan()], but in a different order |
| 145 | |
| 146 | Presumably faster as it incurs fewer copies |
| 147 | |
| 148 | Parameters |
| 149 | ---------- |
| 150 | arr1d : ndarray |
| 151 | Array to remove nans from |
| 152 | overwrite_input : bool |
| 153 | True if `arr1d` can be modified in place |
| 154 | |
| 155 | Returns |
| 156 | ------- |
| 157 | res : ndarray |
| 158 | Array with nan elements removed |
| 159 | overwrite_input : bool |
| 160 | True if `res` can be modified in place, given the constraint on the |
| 161 | input |
| 162 | """ |
| 163 | if arr1d.dtype == object: |
| 164 | # object arrays do not support `isnan` (gh-9009), so make a guess |
| 165 | c = np.not_equal(arr1d, arr1d, dtype=bool) |
| 166 | else: |
| 167 | c = np.isnan(arr1d) |
| 168 | |
| 169 | s = np.nonzero(c)[0] |
| 170 | if s.size == arr1d.size: |
| 171 | warnings.warn("All-NaN slice encountered", RuntimeWarning, |
| 172 | stacklevel=6) |
| 173 | return arr1d[:0], True |
| 174 | elif s.size == 0: |
| 175 | return arr1d, overwrite_input |
| 176 | else: |
| 177 | if not overwrite_input: |
| 178 | arr1d = arr1d.copy() |
| 179 | # select non-nans at end of array |
| 180 | enonan = arr1d[-s.size:][~c[-s.size:]] |
| 181 | # fill nans in beginning of array with non-nans of end |
| 182 | arr1d[s[:enonan.size]] = enonan |
| 183 | |
| 184 | return arr1d[:-s.size], True |
| 185 | |
| 186 | |
| 187 | def _divide_by_count(a, b, out=None): |
no test coverage detected