class_docstr: Compute element-wise time elapsed between time index and a reference start time.
  
  Creates a column(s) which represents: `t` - `start`, where `start` is
  a reference time and `t` is the time index. The type of `start` must be
  compatible with the index of `X` used in `.fit()` and `.transform()`.
  
  The output can be converted to an integer representing the number of periods
  elapsed since the start time by setting `to_numeric=True`. The period is
  determined by the frequency of the index. For example, if the `freq` of
  the index is "MS" or "M" then the output is the integer number of months
  between `t` and `start`.
  
  Parameters
  ----------
  start : a list of start times, optional, default=None (use earliest time in index)
      a "start time" can be one of the following types:
  
      * int: Start time to compute the time elapsed, use when index is integer.
      * time-like: `Period` or `datetime`
          Start time to compute the time elapsed.
      * str: String is converted to datetime or period, depending on the index type,             to give the start time.
  
  to_numeric : string, optional (default=True)
      Return the integer number of periods elapsed since `start`; the period
      is defined by the frequency of the data. Converts datetime types to
      pd.Period before calculating time differences.
  freq : 'str', optional, default=None
      Only used when X has a pd.DatetimeIndex without a specified frequency.
      Specifies the frequency of the index of your data. The string should
      match a pandas offset alias:
      https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases
  keep_original_columns :  boolean, optional, default=False
      Keep original columns in X passed to `.transform()`.
  positive_only :  boolean, optional, default=False
      Clips negative values to zero when `to_numeric` is True.
  
  Examples
  --------
  >>> from sktime.datasets import load_airline
  >>> from sktime.transformations.series.time_since import TimeSince
  >>> X = load_airline()
  
      Create a single column with time elapsed since start date of time series.
      The output is in units of integer number of months, same as the index `freq`.
  
  >>> transformer = TimeSince()
  >>> Xt = transformer.fit_transform(X)
  
      Create multiple columns with different start times. The output is in units
      of integer number of months, same as the index `freq`.
  
  >>> transformer = TimeSince(["2000-01", "2000-02"])
  >>> Xt = transformer.fit_transform(X)
class_docstr_tok: ["Compute","element-wise","time","elapsed","between","time","index","and","a","reference","start","time",".","Creates","a","column","(","s",")","which","represents",":","`","t","`","-","`","start","`",",","where","`","start","`","is","a","reference","time","and","`","t","`","is","the","time","index",".","The","type","of","`","start","`","must","be","compatible","with","the","index","of","`","X","`","used","in","`",".fit","(",")","`","and","`",".transform","(",")","`",".","The","output","can","be","converted","to","an","integer","representing","the","number","of","periods","elapsed","since","the","start","time","by","setting","`","to_numeric=True","`",".","The","period","is","determined","by","the","frequency","of","the","index",".","For","example",",","if","the","`","freq","`","of","the","index","is","``","MS","''","or","``","M","''","then","the","output","is","the","integer","number","of","months","between","`","t","`","and","`","start","`",".","Parameters","--","--","--","--","--","start",":","a","list","of","start","times",",","optional",",","default=None","(","use","earliest","time","in","index",")","a","``","start","time","''","can","be","one","of","the","following","types",":","*","int",":","Start","time","to","compute","the","time","elapsed",",","use","when","index","is","integer",".","*","time-like",":","`","Period","`","or","`","datetime","`","Start","time","to","compute","the","time","elapsed",".","*","str",":","String","is","converted","to","datetime","or","period",",","depending","on","the","index","type",",","to","give","the","start","time",".","to_numeric",":","string",",","optional","(","default=True",")","Return","the","integer","number","of","periods","elapsed","since","`","start","`",";","the","period","is","defined","by","the","frequency","of","the","data",".","Converts","datetime","types","to","pd.Period","before","calculating","time","differences",".","freq",":","'str","'",",","optional",",","default=None","Only","used","when","X","has","a","pd.DatetimeIndex","without","a","specified","frequency",".","Specifies","the","frequency","of","the","index","of","your","data",".","The","string","should","match","a","pandas","offset","alias",":","https",":","\/\/pandas.pydata.org\/pandas-docs\/stable\/user_guide\/timeseries.html","#","offset-aliases","keep_original_columns",":","boolean",",","optional",",","default=False","Keep","original","columns","in","X","passed","to","`",".transform","(",")","`",".","positive_only",":","boolean",",","optional",",","default=False","Clips","negative","values","to","zero","when","`","to_numeric","`","is","True",".","Examples","--","--","--","--",">",">",">","from","sktime.datasets","import","load_airline",">",">",">","from","sktime.transformations.series.time_since","import","TimeSince",">",">",">","X","=","load_airline","(",")","Create","a","single","column","with","time","elapsed","since","start","date","of","time","series",".","The","output","is","in","units","of","integer","number","of","months",",","same","as","the","index","`","freq","`",".",">",">",">","transformer","=","TimeSince","(",")",">",">",">","Xt","=","transformer.fit_transform","(","X",")","Create","multiple","columns","with","different","start","times",".","The","output","is","in","units","of","integer","number","of","months",",","same","as","the","index","`","freq","`",".",">",">",">","transformer","=","TimeSince","(","[","``","2000-01","''",",","``","2000-02","''","]",")",">",">",">","Xt","=","transformer.fit_transform","(","X",")"]
docstr: Fit transformer to X and y.
  
  private _fit containing the core logic, called from fit
  
  Parameters
  ----------
  X : Series or Panel of mtype X_inner_mtype
      if X_inner_mtype is list, _fit must support all types in it
      Data to fit transform to
  y : Series or Panel of mtype y_inner_mtype, default=None
      Additional data, e.g., labels for transformation
  
  Returns
  -------
  self: reference to self
docstr_tok: ["Fit","transformer","to","X","and","y.","private","_fit","containing","the","core","logic",",","called","from","fit","Parameters","--","--","--","--","--","X",":","Series","or","Panel","of","mtype","X_inner_mtype","if","X_inner_mtype","is","list",",","_fit","must","support","all","types","in","it","Data","to","fit","transform","to","y",":","Series","or","Panel","of","mtype","y_inner_mtype",",","default=None","Additional","data",",","e.g.",",","labels","for","transformation","Returns","--","--","--","-","self",":","reference","to","self"]
code: def _fit(self, X, y=None):
      """Fit transformer to X and y.
  
      private _fit containing the core logic, called from fit
  
      Parameters
      ----------
      X : Series or Panel of mtype X_inner_mtype
          if X_inner_mtype is list, _fit must support all types in it
          Data to fit transform to
      y : Series or Panel of mtype y_inner_mtype, default=None
          Additional data, e.g., labels for transformation
  
      Returns
      -------
      self: reference to self
      """
      time_index = _get_time_index(X)
  
      if pd.api.types.is_numeric_dtype(time_index):
          if self.freq:
              warnings.warn(
                  "Index is integer type. `freq` will be ignored.",
                  stacklevel=2,
              )
          self.freq_ = None
      elif isinstance(time_index, (pd.DatetimeIndex, pd.PeriodIndex)):
          # Chooses first non None value
          self.freq_ = (
              time_index.freqstr
              or self.freq
              or pd.infer_freq(time_index)
          )
          if self.freq_ is None:
              raise ValueError(
                  "X has no known frequency and none is supplied"
              )
          if (
              (self.freq_ == time_index.freqstr)
              and (self.freq_ != self.freq)
              and (self.freq)
          ):
              warnings.warn(
                  f"Using frequency from index: {time_index.freq}, which "
                  f"does not match the frequency given: {self.freq}.",
                  stacklevel=2,
              )
      else:
          raise ValueError(
              "Index must be of type int, datetime, or period."
          )
  
      self.start_ = []
      if self.start is None:
          self.start_.append(time_index.min())
      else:
          for start in self.start:
              if start is None:
                  self.start_.append(time_index.min())
              elif isinstance(start, str):
                  if isinstance(time_index, pd.PeriodIndex):
                      self.start_.append(pd.Period(start))
                  else:
                      self.start_.append(pd.to_datetime(start))
              else:
                  self.start_.append(start)
  
      # Check `start_` is compatible with index
      for start_ in self.start_:
          if isinstance(
              time_index, pd.DatetimeIndex
          ) and not isinstance(start_, datetime.datetime):
              raise ValueError(
                  f"start_={start_} incompatible with a "
                  f"datetime index. Check that `start` is of type "
                  f"datetime or a pd.Datetime parsable string."
              )
          elif isinstance(
              time_index, pd.PeriodIndex
          ) and not isinstance(start_, pd.Period):
              raise ValueError(
                  f"start_={start_} incompatible with a "
                  f"Period index. Check that `start` is of type "
                  f"pd.Period or a pd.Period parsable string."
              )
          elif pd.api.types.is_numeric_dtype(time_index):
              if not isinstance(start_, (int, np.integer)):
                  raise ValueError(
                      f"start_={start_} incompatible with a numeric index."
                      f"Check that `start` is an integer."
                  )
  
      return self
  
file_path: sktime/sktime/transformations/series/time_since.py
imports: from __future__ import annotations
  import datetime
  import warnings
  from string import digits
  import numpy
  import pandas
  from pandas.tseries.frequencies import get_period_alias
  from sktime.transformations.base import BaseTransformer
label_desc: Use image node_id 2 for calling the TimeSince obj's underlying member method code with example usage: obj._fit(X, y) and returns: self