parameters: (xvalues, yvalues, method='linear', limit=None,
                     limit_direction='forward', limit_area=None, fill_value=None,
                     bounds_error=False, order=None, **kwargs)
docstring: Logic for the 1-d interpolation.  The result should be 1-d, inputs
      xvalues and yvalues will each be 1-d arrays of the same length.
  
      Bounds_error is currently hardcoded to False since non-scipy ones don't
      take it as an argumnet.
docstring_summary: Logic for the 1-d interpolation.  The result should be 1-d, inputs
      xvalues and yvalues will each be 1-d arrays of the same length.
docstring_tokens: Logic for the 1 - d interpolation . The result should be 1 - d inputs xvalues and yvalues will each be 1 - d arrays of the same length .
function: def interpolate_1d(xvalues, yvalues, method='linear', limit=None,
                     limit_direction='forward', limit_area=None, fill_value=None,
                     bounds_error=False, order=None, **kwargs):
      """
      Logic for the 1-d interpolation.  The result should be 1-d, inputs
      xvalues and yvalues will each be 1-d arrays of the same length.
  
      Bounds_error is currently hardcoded to False since non-scipy ones don't
      take it as an argumnet.
      """
      # Treat the original, non-scipy methods first.
  
      invalid = isna(yvalues)
      valid = ~invalid
  
      if not valid.any():
          # have to call np.asarray(xvalues) since xvalues could be an Index
          # which can't be mutated
          result = np.empty_like(np.asarray(xvalues), dtype=np.float64)
          result.fill(np.nan)
          return result
  
      if valid.all():
          return yvalues
  
      if method == 'time':
          if not getattr(xvalues, 'is_all_dates', None):
              # if not issubclass(xvalues.dtype.type, np.datetime64):
              raise ValueError('time-weighted interpolation only works '
                               'on Series or DataFrames with a '
                               'DatetimeIndex')
          method = 'values'
  
      valid_limit_directions = ['forward', 'backward', 'both']
      limit_direction = limit_direction.lower()
      if limit_direction not in valid_limit_directions:
          msg = ('Invalid limit_direction: expecting one of {valid!r}, '
                 'got {invalid!r}.')
          raise ValueError(msg.format(valid=valid_limit_directions,
                                      invalid=limit_direction))
  
      if limit_area is not None:
          valid_limit_areas = ['inside', 'outside']
          limit_area = limit_area.lower()
          if limit_area not in valid_limit_areas:
              raise ValueError('Invalid limit_area: expecting one of {}, got '
                               '{}.'.format(valid_limit_areas, limit_area))
  
      # default limit is unlimited GH #16282
      if limit is None:
          # limit = len(xvalues)
          pass
      elif not is_integer(limit):
          raise ValueError('Limit must be an integer')
      elif limit < 1:
          raise ValueError('Limit must be greater than 0')
  
      from pandas import Series
      ys = Series(yvalues)
  
      # These are sets of index pointers to invalid values... i.e. {0, 1, etc...
      all_nans = set(np.flatnonzero(invalid))
      start_nans = set(range(ys.first_valid_index()))
      end_nans = set(range(1 + ys.last_valid_index(), len(valid)))
      mid_nans = all_nans - start_nans - end_nans
  
      # Like the sets above, preserve_nans contains indices of invalid values,
      # but in this case, it is the final set of indices that need to be
      # preserved as NaN after the interpolation.
  
      # For example if limit_direction='forward' then preserve_nans will
      # contain indices of NaNs at the beginning of the series, and NaNs that
      # are more than'limit' away from the prior non-NaN.
  
      # set preserve_nans based on direction using _interp_limit
      if limit_direction == 'forward':
          preserve_nans = start_nans | set(_interp_limit(invalid, limit, 0))
      elif limit_direction == 'backward':
          preserve_nans = end_nans | set(_interp_limit(invalid, 0, limit))
      else:
          # both directions... just use _interp_limit
          preserve_nans = set(_interp_limit(invalid, limit, limit))
  
      # if limit_area is set, add either mid or outside indices
      # to preserve_nans GH #16284
      if limit_area == 'inside':
          # preserve NaNs on the outside
          preserve_nans |= start_nans | end_nans
      elif limit_area == 'outside':
          # preserve NaNs on the inside
          preserve_nans |= mid_nans
  
      # sort preserve_nans and covert to list
      preserve_nans = sorted(preserve_nans)
  
      xvalues = getattr(xvalues, 'values', xvalues)
      yvalues = getattr(yvalues, 'values', yvalues)
      result = yvalues.copy()
  
      if method in ['linear', 'time', 'index', 'values']:
          if method in ('values', 'index'):
              inds = np.asarray(xvalues)
              # hack for DatetimeIndex, #1646
              if needs_i8_conversion(inds.dtype.type):
                  inds = inds.view(np.int64)
              if inds.dtype == np.object_:
                  inds = lib.maybe_convert_objects(inds)
          else:
              inds = xvalues
          result[invalid] = np.interp(inds[invalid], inds[valid], yvalues[valid])
          result[preserve_nans] = np.nan
          return result
  
      sp_methods = ['nearest', 'zero', 'slinear', 'quadratic', 'cubic',
                    'barycentric', 'krogh', 'spline', 'polynomial',
                    'from_derivatives', 'piecewise_polynomial', 'pchip', 'akima']
  
      if method in sp_methods:
          inds = np.asarray(xvalues)
          # hack for DatetimeIndex, #1646
          if issubclass(inds.dtype.type, np.datetime64):
              inds = inds.view(np.int64)
          result[invalid] = _interpolate_scipy_wrapper(inds[valid],
                                                       yvalues[valid],
                                                       inds[invalid],
                                                       method=method,
                                                       fill_value=fill_value,
                                                       bounds_error=bounds_error,
                                                       order=order, **kwargs)
          result[preserve_nans] = np.nan
          return result
function_tokens: def interpolate_1d ( xvalues , yvalues , method = 'linear' , limit = None , limit_direction = 'forward' , limit_area = None , fill_value = None , bounds_error = False , order = None , * * kwargs ) : # Treat the original, non-scipy methods first. invalid = isna ( yvalues ) valid = ~ invalid if not valid . any ( ) : # have to call np.asarray(xvalues) since xvalues could be an Index # which can't be mutated result = np . empty_like ( np . asarray ( xvalues ) , dtype = np . float64 ) result . fill ( np . nan ) return result if valid . all ( ) : return yvalues if method == 'time' : if not getattr ( xvalues , 'is_all_dates' , None ) : # if not issubclass(xvalues.dtype.type, np.datetime64): raise ValueError ( 'time-weighted interpolation only works ' 'on Series or DataFrames with a ' 'DatetimeIndex' ) method = 'values' valid_limit_directions = [ 'forward' , 'backward' , 'both' ] limit_direction = limit_direction . lower ( ) if limit_direction not in valid_limit_directions : msg = ( 'Invalid limit_direction: expecting one of {valid!r}, ' 'got {invalid!r}.' ) raise ValueError ( msg . format ( valid = valid_limit_directions , invalid = limit_direction ) ) if limit_area is not None : valid_limit_areas = [ 'inside' , 'outside' ] limit_area = limit_area . lower ( ) if limit_area not in valid_limit_areas : raise ValueError ( 'Invalid limit_area: expecting one of {}, got ' '{}.' . format ( valid_limit_areas , limit_area ) ) # default limit is unlimited GH #16282 if limit is None : # limit = len(xvalues) pass elif not is_integer ( limit ) : raise ValueError ( 'Limit must be an integer' ) elif limit < 1 : raise ValueError ( 'Limit must be greater than 0' ) from pandas import Series ys = Series ( yvalues ) # These are sets of index pointers to invalid values... i.e. {0, 1, etc... all_nans = set ( np . flatnonzero ( invalid ) ) start_nans = set ( range ( ys . first_valid_index ( ) ) ) end_nans = set ( range ( 1 + ys . last_valid_index ( ) , len ( valid ) ) ) mid_nans = all_nans - start_nans - end_nans # Like the sets above, preserve_nans contains indices of invalid values, # but in this case, it is the final set of indices that need to be # preserved as NaN after the interpolation. # For example if limit_direction='forward' then preserve_nans will # contain indices of NaNs at the beginning of the series, and NaNs that # are more than'limit' away from the prior non-NaN. # set preserve_nans based on direction using _interp_limit if limit_direction == 'forward' : preserve_nans = start_nans | set ( _interp_limit ( invalid , limit , 0 ) ) elif limit_direction == 'backward' : preserve_nans = end_nans | set ( _interp_limit ( invalid , 0 , limit ) ) else : # both directions... just use _interp_limit preserve_nans = set ( _interp_limit ( invalid , limit , limit ) ) # if limit_area is set, add either mid or outside indices # to preserve_nans GH #16284 if limit_area == 'inside' : # preserve NaNs on the outside preserve_nans |= start_nans | end_nans elif limit_area == 'outside' : # preserve NaNs on the inside preserve_nans |= mid_nans # sort preserve_nans and covert to list preserve_nans = sorted ( preserve_nans ) xvalues = getattr ( xvalues , 'values' , xvalues ) yvalues = getattr ( yvalues , 'values' , yvalues ) result = yvalues . copy ( ) if method in [ 'linear' , 'time' , 'index' , 'values' ] : if method in ( 'values' , 'index' ) : inds = np . asarray ( xvalues ) # hack for DatetimeIndex, #1646 if needs_i8_conversion ( inds . dtype . type ) : inds = inds . view ( np . int64 ) if inds . dtype == np . object_ : inds = lib . maybe_convert_objects ( inds ) else : inds = xvalues result [ invalid ] = np . interp ( inds [ invalid ] , inds [ valid ] , yvalues [ valid ] ) result [ preserve_nans ] = np . nan return result sp_methods = [ 'nearest' , 'zero' , 'slinear' , 'quadratic' , 'cubic' , 'barycentric' , 'krogh' , 'spline' , 'polynomial' , 'from_derivatives' , 'piecewise_polynomial' , 'pchip' , 'akima' ] if method in sp_methods : inds = np . asarray ( xvalues ) # hack for DatetimeIndex, #1646 if issubclass ( inds . dtype . type , np . datetime64 ) : inds = inds . view ( np . int64 ) result [ invalid ] = _interpolate_scipy_wrapper ( inds [ valid ] , yvalues [ valid ] , inds [ invalid ] , method = method , fill_value = fill_value , bounds_error = bounds_error , order = order , * * kwargs ) result [ preserve_nans ] = np . nan return result