code: def _safe_minmax(values):
      
  
      # Nan and inf guarded min and max
      isfinite = np.isfinite(values)
      if np.any(isfinite):
          # Only use finite values
          values = values[isfinite]
  
      minval = np.min(values)
      maxval = np.max(values)
  
      return minval, maxval
docs: Calculate min and max of array with guards for nan and inf.