def forecast(x, h=None, **kwargs):
    '''
  Generate a forecast for the time series x, using ets if x is non-seasonal 
  or has frequency less than 13, and stlf if x is periodic with frequency 
  above 13.
  
  Args:
    x: an R time series, obtained from converters.ts(), or a Pandas Series
      with the correct index (e.g. from converters.sequence_as_series().
    h: the forecast horizon
    level: A number or list/tuple of prediction interval confidence values.
      Default is 80% and 95% intervals.
    robust: Default False. If True, missing values are filled before 
      forecasting and outliers are identified and replaced with tsclean().
    lam : BoxCox transformation parameter. The default is R's NULL value.
      If NULL, no transformation is applied. Otherwise, a Box-Cox 
      transformation is applied before forecasting and inverted after.
    find_frequency: Default False. If True, function will try to determine 
      the series frequency from the data.
    allow_multiplicative_trend: Default is False. If True, consider models 
      with a multiplicative trend component. That type of model may grow 
      explosively.
        
  Returns:
    If x is an R ts object, an R forecast is returned. If x is a Pandas 
    Series, a Pandas Data Frame is returned.
  '''
    x, is_pandas = converters.to_ts(x)
    h = _get_horizon(x, h)
    kwargs = converters.translate_kwargs(**kwargs)
    out = fc.forecast(x, h=h, **kwargs)
    return converters.forecast_out(out, is_pandas)
def forecast(x, h=None, **kwargs):
  '''
  Generate a forecast for the time series x, using ets if x is non-seasonal 
  or has frequency less than 13, and stlf if x is periodic with frequency 
  above 13.
  
  Args:
    x: an R time series, obtained from converters.ts(), or a Pandas Series
      with the correct index (e.g. from converters.sequence_as_series().
    h: the forecast horizon
    level: A number or list/tuple of prediction interval confidence values.
      Default is 80% and 95% intervals.
    robust: Default False. If True, missing values are filled before 
      forecasting and outliers are identified and replaced with tsclean().
    lam : BoxCox transformation parameter. The default is R's NULL value.
      If NULL, no transformation is applied. Otherwise, a Box-Cox 
      transformation is applied before forecasting and inverted after.
    find_frequency: Default False. If True, function will try to determine 
      the series frequency from the data.
    allow_multiplicative_trend: Default is False. If True, consider models 
      with a multiplicative trend component. That type of model may grow 
      explosively.
        
  Returns:
    If x is an R ts object, an R forecast is returned. If x is a Pandas 
    Series, a Pandas Data Frame is returned.
  '''
  x, is_pandas = converters.to_ts(x)
  h = _get_horizon(x, h)
  kwargs = converters.translate_kwargs(**kwargs)
  out = fc.forecast(x, h=h, **kwargs)
  return converters.forecast_out(out, is_pandas)
def nsdiffs(x, **kwargs):
    '''
  Estimates the number of seasonal differences to take on the time series, 
  x, to reach stationarity. For this function, x must be a seasonal series.
  
  Args:
    x: an R time series or a Pandas Series
    m: Seasonal period. Default is frequency(x). No other value makes sense.
    test : Test to use to determine number of seasonal differences.
        Default is 'ocsb' for the Osborn-Chui-Smith-Birchenhall  test. 
        The alternative is 'ch' for the Canova-Hansen test. 
    max_D: Maximum number of seasonal differences to try. Default is 1.
    
  Returns:
    The number of seasonal differences to take
  '''
    x, _ = converters.to_ts(x)
    kwargs = converters.translate_kwargs(**kwargs)
    return fc.nsdiffs(x, **kwargs)[0]
def ndiffs(x, **kwargs):
    '''
  Estimates the number of first differences (non-seasonal) to take on the 
  time series, x, to reach stationarity.
  
  Args:
    x: an R time series or a Pandas Series
    alpha: Default 0.05, the level of the test used
    test : Test to use to determine number of first differences. Default 
        is 'kpss', for the KPSS test. Other values are 'adf' for augmented 
        Dickey-Fuller, or 'pp' for Phillips-Perron.
    max_d: max number of differences to try. Default is 2.
    
  Returns:
    The number of differences to take
  '''
    x, _ = converters.to_ts(x)
    kwargs = converters.translate_kwargs(**kwargs)
    return fc.ndiffs(x, **kwargs)[0]
def stl(x, s_window, **kwargs):
    '''
  Perform a decomposition of the time series x into seasonal, trend and 
  remainder components using loess. Most of the arguments listed below are 
  in **kwargs, and all of those arguments have sensible defaults. Usually 
  only the mandatory s_window paramter has to be set.
  
  Args:
    x: an R time series, obtained from converters.ts(), or a Pandas Series
      with the correct index (e.g. from converters.sequence_as_series().
    s_window : either 'periodic' or the span (in lags) of the 
      loess window for seasonal extraction, which should be odd.
      This has no default.
    s_degree : Default 0, should be 0 or 1. Degree of local polynomial 
      for seasonal extraction.
    t_window : The span (in lags) of the loess window for trend extraction, 
      which should be odd. Default is a sensible, data-dependent value.
      See the R docs for the details.
    t_degree : Default 0, should be 0 or 1. Degree of local polynomial 
      for trend extraction.
    l_window : Span in lags of the loess window used to low-pass filter each 
      seasonal subseries. The default is first odd number greater than or 
      equal to frequency, which is recommmended.
    s_jump, t_jump, l_jump : integer parameters (min. 1) to increase speed of 
      each smoother by skipping data points.
    l_degree : Default is t.window, must be 0 or 1. Degree of local polynomial 
      for subseries low-pass filter.
    robust : Default is False. If True, robust loess fitting used.
    inner : number of backfitting iterations
    outer : number of outer robustness iterations
    na_action : Default is na.fail, which means that the user has to fill or 
      remove any missing values. If used, it must be an object that maps to 
      an R function, obtained from rpy2.
      
  Returns:
    If x is an R ts object, an R object of class 'stl' is returned. 
    If x is a Pandas Series, a Pandas Data Frame is returned.
  '''
    x, is_pandas = converters.to_ts(x)
    kwargs['s.window'] = s_window
    kwargs = converters.translate_kwargs(**kwargs)
    out = stats.stl(x, **kwargs)
    return converters.decomposition_out(out, is_pandas)
def nsdiffs(x, **kwargs):
  '''
  Estimates the number of seasonal differences to take on the time series, 
  x, to reach stationarity. For this function, x must be a seasonal series.
  
  Args:
    x: an R time series or a Pandas Series
    m: Seasonal period. Default is frequency(x). No other value makes sense.
    test : Test to use to determine number of seasonal differences.
        Default is 'ocsb' for the Osborn-Chui-Smith-Birchenhall  test. 
        The alternative is 'ch' for the Canova-Hansen test. 
    max_D: Maximum number of seasonal differences to try. Default is 1.
    
  Returns:
    The number of seasonal differences to take
  '''
  x, _ = converters.to_ts(x)
  kwargs = converters.translate_kwargs(**kwargs)
  return fc.nsdiffs(x, **kwargs)[0]
def ndiffs(x, **kwargs):
  '''
  Estimates the number of first differences (non-seasonal) to take on the 
  time series, x, to reach stationarity.
  
  Args:
    x: an R time series or a Pandas Series
    alpha: Default 0.05, the level of the test used
    test : Test to use to determine number of first differences. Default 
        is 'kpss', for the KPSS test. Other values are 'adf' for augmented 
        Dickey-Fuller, or 'pp' for Phillips-Perron.
    max_d: max number of differences to try. Default is 2.
    
  Returns:
    The number of differences to take
  '''
  x, _ = converters.to_ts(x)
  kwargs = converters.translate_kwargs(**kwargs)
  return fc.ndiffs(x, **kwargs)[0]
def stl(x, s_window, **kwargs):
  '''
  Perform a decomposition of the time series x into seasonal, trend and 
  remainder components using loess. Most of the arguments listed below are 
  in **kwargs, and all of those arguments have sensible defaults. Usually 
  only the mandatory s_window paramter has to be set.
  
  Args:
    x: an R time series, obtained from converters.ts(), or a Pandas Series
      with the correct index (e.g. from converters.sequence_as_series().
    s_window : either 'periodic' or the span (in lags) of the 
      loess window for seasonal extraction, which should be odd.
      This has no default.
    s_degree : Default 0, should be 0 or 1. Degree of local polynomial 
      for seasonal extraction.
    t_window : The span (in lags) of the loess window for trend extraction, 
      which should be odd. Default is a sensible, data-dependent value.
      See the R docs for the details.
    t_degree : Default 0, should be 0 or 1. Degree of local polynomial 
      for trend extraction.
    l_window : Span in lags of the loess window used to low-pass filter each 
      seasonal subseries. The default is first odd number greater than or 
      equal to frequency, which is recommmended.
    s_jump, t_jump, l_jump : integer parameters (min. 1) to increase speed of 
      each smoother by skipping data points.
    l_degree : Default is t.window, must be 0 or 1. Degree of local polynomial 
      for subseries low-pass filter.
    robust : Default is False. If True, robust loess fitting used.
    inner : number of backfitting iterations
    outer : number of outer robustness iterations
    na_action : Default is na.fail, which means that the user has to fill or 
      remove any missing values. If used, it must be an object that maps to 
      an R function, obtained from rpy2.
      
  Returns:
    If x is an R ts object, an R object of class 'stl' is returned. 
    If x is a Pandas Series, a Pandas Data Frame is returned.
  '''
  x, is_pandas = converters.to_ts(x)
  kwargs['s.window'] = s_window
  kwargs = converters.translate_kwargs(**kwargs)
  out = stats.stl(x, **kwargs)
  return converters.decomposition_out(out, is_pandas)
def tsclean(x, **kwargs):
    '''
  Identify and replace outliers. Uses loess for non-seasonal series and 
  an STL decomposition for seasonal series. Optionally fills missing values.

  Args:
    x: an R time series, obtained from converters.ts(), or a Pandas Series
      with the correct index (e.g. from converters.sequence_as_series().
    replace_missing: Default True. 
      If True, use na_interp to fill missing values in x.
    lam: optional BoxCox transformation parameter.
    
  Returns:
    If x is an R ts object, an R time series is returned. If x is a Pandas 
    Series, a Pandas Series is returned. In either case, outliers are replaced 
    and optionally, missing values are filled.
  '''
    x, is_pandas = converters.to_ts(x)
    kwargs = converters.translate_kwargs(**kwargs)
    out = fc.tsclean(x, **kwargs)
    return converters.series_out(out, is_pandas)
def tsclean(x, **kwargs):
  '''
  Identify and replace outliers. Uses loess for non-seasonal series and 
  an STL decomposition for seasonal series. Optionally fills missing values.

  Args:
    x: an R time series, obtained from converters.ts(), or a Pandas Series
      with the correct index (e.g. from converters.sequence_as_series().
    replace_missing: Default True. 
      If True, use na_interp to fill missing values in x.
    lam: optional BoxCox transformation parameter.
    
  Returns:
    If x is an R ts object, an R time series is returned. If x is a Pandas 
    Series, a Pandas Series is returned. In either case, outliers are replaced 
    and optionally, missing values are filled.
  '''
  x, is_pandas = converters.to_ts(x)
  kwargs = converters.translate_kwargs(**kwargs)
  out = fc.tsclean(x, **kwargs)
  return converters.series_out(out, is_pandas)