code: def _median_nancheck(data, result, axis):
      """
      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 median function.
      axis : int
          Axis along which the median was computed.
  
      Returns
      -------
      result : scalar or ndarray
          Median or NaN in axes which contained NaN in the input.  If the input
          was an array, NaN will be inserted in-place.  If a scalar, either the
          input itself or a scalar NaN.
      """
      if data.size == 0:
          return result
      potential_nans = data.take(-1, axis=axis)
      n = np.isnan(potential_nans)
      # masked NaN values are ok, although for masked the copyto may fail for
      # unmasked ones (this was always broken) when the result is a scalar.
      if np.ma.isMaskedArray(n):
          n = n.filled(False)
  
      if not n.any():
          return result
  
      # Without given output, it is possible that the current result is a
      # numpy scalar, which is not writeable.  If so, just return nan.
      if isinstance(result, np.generic):
          return potential_nans
  
      # Otherwise copy NaNs (if there are any)
      np.copyto(result, potential_nans, where=n)
      return result
  
imports: import os
  import sys
  import textwrap
  import types
  import re
  import warnings
  import functools
  import platform
  from .._utils import set_module
  from numpy.core.numerictypes import issubclass_, issubsctype, issubdtype
  from numpy.core import ndarray, ufunc, asarray
  import numpy
label_desc: Use image node_id 17 for calling a global function with example usage: _median_nancheck(data, result, axis) and returns: result, result, result, potential_nans