nodes: 0, module; 1, function_definition; 2, function_name:interpolate_nans_1d; 3, parameters; 4, block; 5, identifier:x; 6, identifier:y; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, if_statement; 14, return_statement; 15, identifier:kind; 16, string; 17, comment:"""Interpolate NaN values in y.
  
      Interpolate NaN values in the y dimension. Works with unsorted x values.
  
      Parameters
      ----------
      x : array-like
          1-dimensional array of numeric x-values
      y : array-like
          1-dimensional array of numeric y-values
      kind : string
          specifies the kind of interpolation x coordinate - 'linear' or 'log', optional.
          Defaults to 'linear'.
  
      Returns
      -------
          An array of the y coordinate data with NaN values interpolated.
  
      """; 18, assignment; 19, assignment; 20, assignment; 21, assignment; 22, comparison_operator:kind == 'linear'; 23, block; 24, elif_clause; 25, else_clause; 26, subscript; 27, string_content:linear; 28, identifier:x_sort_args; 29, call; 30, identifier:x; 31, subscript; 32, identifier:y; 33, subscript; 34, identifier:nans; 35, call; 36, identifier:kind; 37, string; 38, expression_statement; 39, comparison_operator:kind == 'log'; 40, block; 41, block; 42, identifier:y; 43, identifier:x_sort_args; 44, attribute; 45, argument_list; 46, identifier:x; 47, identifier:x_sort_args; 48, identifier:y; 49, identifier:x_sort_args; 50, attribute; 51, argument_list; 52, string_content:linear; 53, assignment; 54, identifier:kind; 55, string; 56, expression_statement; 57, raise_statement; 58, identifier:np; 59, identifier:argsort; 60, identifier:x; 61, identifier:np; 62, identifier:isnan; 63, identifier:y; 64, subscript; 65, call; 66, string_content:log; 67, assignment; 68, call; 69, identifier:y; 70, identifier:nans; 71, attribute; 72, argument_list; 73, subscript; 74, call; 75, identifier:ValueError; 76, argument_list; 77, identifier:np; 78, identifier:interp; 79, subscript; 80, subscript; 81, subscript; 82, identifier:y; 83, identifier:nans; 84, attribute; 85, argument_list; 86, call; 87, identifier:x; 88, identifier:nans; 89, identifier:x; 90, unary_operator; 91, identifier:y; 92, unary_operator; 93, identifier:np; 94, identifier:interp; 95, call; 96, call; 97, subscript; 98, attribute; 99, argument_list; 100, identifier:nans; 101, identifier:nans; 102, attribute; 103, argument_list; 104, attribute; 105, argument_list; 106, identifier:y; 107, unary_operator; 108, string; 109, identifier:format; 110, call; 111, identifier:np; 112, identifier:log; 113, subscript; 114, identifier:np; 115, identifier:log; 116, subscript; 117, identifier:nans; 118, string_content:Unknown option for kind: {0}; 119, identifier:str; 120, argument_list; 121, identifier:x; 122, identifier:nans; 123, identifier:x; 124, unary_operator; 125, identifier:kind; 126, identifier:nans
code: def interpolate_nans_1d(x, y, kind='linear'):
      """Interpolate NaN values in y.
  
      Interpolate NaN values in the y dimension. Works with unsorted x values.
  
      Parameters
      ----------
      x : array-like
          1-dimensional array of numeric x-values
      y : array-like
          1-dimensional array of numeric y-values
      kind : string
          specifies the kind of interpolation x coordinate - 'linear' or 'log', optional.
          Defaults to 'linear'.
  
      Returns
      -------
          An array of the y coordinate data with NaN values interpolated.
  
      """
      x_sort_args = np.argsort(x)
      x = x[x_sort_args]
      y = y[x_sort_args]
      nans = np.isnan(y)
      if kind == 'linear':
          y[nans] = np.interp(x[nans], x[~nans], y[~nans])
      elif kind == 'log':
          y[nans] = np.interp(np.log(x[nans]), np.log(x[~nans]), y[~nans])
      else:
          raise ValueError('Unknown option for kind: {0}'.format(str(kind)))
      return y[x_sort_args]