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: Transform X and return a transformed version.
  
  private _transform containing core logic, called from transform
  
  Parameters
  ----------
  X : Series or Panel of mtype X_inner_mtype
      if X_inner_mtype is list, _transform must support all types in it
      Data to be transformed
  y : Series or Panel of mtype y_inner_mtype, default=None
      Additional data, e.g., labels for transformation
  
  Returns
  -------
  transformed version of X
docstr_tok: ["Transform","X","and","return","a","transformed","version",".","private","_transform","containing","core","logic",",","called","from","transform","Parameters","--","--","--","--","--","X",":","Series","or","Panel","of","mtype","X_inner_mtype","if","X_inner_mtype","is","list",",","_transform","must","support","all","types","in","it","Data","to","be","transformed","y",":","Series","or","Panel","of","mtype","y_inner_mtype",",","default=None","Additional","data",",","e.g.",",","labels","for","transformation","Returns","--","--","--","-","transformed","version","of","X"]
code: def _transform(self, X, y=None):
      """Transform X and return a transformed version.
  
      private _transform containing core logic, called from transform
  
      Parameters
      ----------
      X : Series or Panel of mtype X_inner_mtype
          if X_inner_mtype is list, _transform must support all types in it
          Data to be transformed
      y : Series or Panel of mtype y_inner_mtype, default=None
          Additional data, e.g., labels for transformation
  
      Returns
      -------
      transformed version of X
      """
      time_index = _get_time_index(X)
  
      Xt = pd.DataFrame(index=X.index)
      for start_ in self.start_:
          if self.to_numeric:
              if isinstance(time_index, pd.DatetimeIndex):
                  # To support calculating integer time differences when `freq`
                  # is not compatible with timedelta type (e.g., "M", "MS", "Y")
                  # X.index and `start` are first converted to pandas Period.
  
                  # Infer the freq needed to convert to period. We use the
                  # `get_period_alas` helper method from Pandas. This method
                  # maps from a frequency that is compatible with a datetime
                  # index to one that is compatible with a period index
                  # (e.g., "MS" -> "M"). We must strip the freq str of any
                  # integer multiplier (e.g., "15T" -> "T"). This is needed so that
                  # `get_period_alias` returns the correct result.
                  # If `get_period_alias` receives a freq str with a multiplier
                  # (e.g., "15T") it returns `None` which causes errors downstream.
                  freq_ = _remove_digits_from_str(self.freq_)
                  freq_period = get_period_alias(freq_)
  
                  # Convert `start` and `time_index` to period.
                  # Casting `start_` to PeriodIndex using pd.period_range
                  # here so we can later cast it to an int using
                  # `astype(int)` in _get_period_diff_as_int().
                  start_period = pd.period_range(
                      start=start_, periods=1, freq=freq_period
                  )
                  time_index_period = time_index.to_period(
                      freq=freq_period
                  )
                  # Compute time differences.
                  time_deltas = _get_period_diff_as_int(
                      time_index_period, start_period
                  )
  
              elif isinstance(time_index, pd.PeriodIndex):
                  if pd.__version__ < "1.5.0":
                      # Earlier versions of pandas returned incorrect result
                      # when taking a difference between Periods when the frequency
                      # is a multiple of a unit (e.g. "15T"). Solution is to
                      # cast to lowest frequency when taking difference (e.g., "T").
                      freq_ = _remove_digits_from_str(self.freq_)
  
                      # Change freq of `start` and `time_index`.
                      # Casting `start_` to PeriodIndex using pd.period_range
                      # here so we can later cast it to an int using
                      # `astype(int)` in _get_period_diff_as_int().
                      start_period = pd.period_range(
                          start=start_.to_timestamp(),
                          periods=1,
                          freq=freq_,
                      )
                      time_index = time_index.to_timestamp().to_period(
                          freq_
                      )
                  else:
                      # Casting `start_` to PeriodIndex using pd.period_range
                      # here so we can later cast it to an int using
                      # `astype(int)` in _get_period_diff_as_int().
                      start_period = pd.period_range(
                          start=start_, periods=1, freq=self.freq_
                      )
  
                  # Compute time differences.
                  time_deltas = _get_period_diff_as_int(
                      time_index, start_period
                  )
  
              elif pd.api.types.is_numeric_dtype(time_index):
                  time_deltas = time_index - start_
          else:
              time_deltas = time_index - start_
  
          col_name = f"time_since_{start_}"
          Xt[col_name] = time_deltas
  
      if self.to_numeric and self.positive_only:
          Xt = Xt.clip(lower=0)
  
      if self.keep_original_columns:
          Xt = pd.concat([X, Xt], axis=1, copy=True)
  
      return Xt
  
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 3 for calling the TimeSince obj's underlying member method code with example usage: obj._transform(X, y) and returns: Xt