Utility function to check median result from data for NaN values at the end and return NaN in that case. Input result can also be a MaskedArray. Parameters ---------- data : array Sorted input data to median function result : Array or MaskedArray Result of m
(data, result, axis)
| 405 | |
| 406 | |
| 407 | def _median_nancheck(data, result, axis): |
| 408 | """ |
| 409 | Utility function to check median result from data for NaN values at the end |
| 410 | and return NaN in that case. Input result can also be a MaskedArray. |
| 411 | |
| 412 | Parameters |
| 413 | ---------- |
| 414 | data : array |
| 415 | Sorted input data to median function |
| 416 | result : Array or MaskedArray |
| 417 | Result of median function. |
| 418 | axis : int |
| 419 | Axis along which the median was computed. |
| 420 | |
| 421 | Returns |
| 422 | ------- |
| 423 | result : scalar or ndarray |
| 424 | Median or NaN in axes which contained NaN in the input. If the input |
| 425 | was an array, NaN will be inserted in-place. If a scalar, either the |
| 426 | input itself or a scalar NaN. |
| 427 | """ |
| 428 | if data.size == 0: |
| 429 | return result |
| 430 | potential_nans = data.take(-1, axis=axis) |
| 431 | n = np.isnan(potential_nans) |
| 432 | # masked NaN values are ok, although for masked the copyto may fail for |
| 433 | # unmasked ones (this was always broken) when the result is a scalar. |
| 434 | if np.ma.isMaskedArray(n): |
| 435 | n = n.filled(False) |
| 436 | |
| 437 | if not n.any(): |
| 438 | return result |
| 439 | |
| 440 | # Without given output, it is possible that the current result is a |
| 441 | # numpy scalar, which is not writeable. If so, just return nan. |
| 442 | if isinstance(result, np.generic): |
| 443 | return potential_nans |
| 444 | |
| 445 | # Otherwise copy NaNs (if there are any) |
| 446 | np.copyto(result, potential_nans, where=n) |
| 447 | return result |
| 448 | |
| 449 | def _opt_info(): |
| 450 | """ |