class_docstr: Defines univariate time series input. The dataset can include regressors,
  but only one metric is designated as the target metric to forecast.
  
  Loads time series into a standard format. Provides statistics, plotting
  functions, and ability to generate future dataframe for prediction.
  
  Attributes
  ----------
  df: `pandas.DataFrame`
      Data frame containing timestamp and value, with standardized column names for internal use
      (TIME_COL, VALUE_COL). Rows are sorted by time index, and missing gaps between dates are filled
      in so that dates are spaced at regular intervals. Values are adjusted for anomalies
      according to ``anomaly_info``.
      The index can be timezone aware (but TIME_COL is not).
  y: `pandas.Series`, dtype float64
      Value of time series to forecast.
  time_stats: `dict`
      Summary statistics about the timestamp column.
  value_stats: `dict`
      Summary statistics about the value column.
  original_time_col: `str`
      Name of time column in original input data.
  original_value_col: `str`
      Name of value column in original input data.
  regressor_cols: `list` [`str`]
      A list of regressor columns in the training and prediction DataFrames.
  lagged_regressor_cols: `list` [`str`]
      A list of additional columns needed for lagged regressors in the training and prediction DataFrames.
  last_date_for_val: `datetime.datetime` or None, default None
      Date or timestamp corresponding  to last non-null value in ``df[original_value_col]``.
  last_date_for_reg: `datetime.datetime` or None, default None
      Date or timestamp corresponding to last non-null value in ``df[regressor_cols]``.
      If ``regressor_cols`` is None, ``last_date_for_reg`` is None.
  last_date_for_lag_reg: `datetime.datetime` or None, default None
      Date or timestamp corresponding to last non-null value in ``df[lagged_regressor_cols]``.
      If ``lagged_regressor_cols`` is None, ``last_date_for_lag_reg`` is None.
  train_end_date: `datetime.datetime`
      Last date or timestamp in ``fit_df``. It is always less than or equal to
      minimum non-null values of ``last_date_for_val`` and ``last_date_for_reg``.
  fit_cols: `list` [`str`]
      A list of columns used in the training and prediction DataFrames.
  fit_df: `pandas.DataFrame`
      Data frame containing timestamp and value, with standardized column names for internal use.
      Will be used for fitting (train, cv, backtest).
  fit_y: `pandas.Series`, dtype float64
      Value of time series for fit_df.
  freq: `str`
      timeseries frequency, DateOffset alias, e.g. {'T' (minute), 'H', D', 'W', 'M' (month end), 'MS' (month start),
      'Y' (year end), 'Y' (year start)}
      See https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases
  anomaly_info : `dict` or `list` [`dict`] or None, default None
      Anomaly adjustment info. Anomalies in ``df``
      are corrected before any forecasting is done.
      See ``self.load_data()``
  df_before_adjustment : `pandas.DataFrame` or None, default None
      ``self.df`` before adjustment by ``anomaly_info``.
      Used by ``self.plot()`` to show the adjustment.
class_docstr_tok: ["Defines","univariate","time","series","input",".","The","dataset","can","include","regressors",",","but","only","one","metric","is","designated","as","the","target","metric","to","forecast",".","Loads","time","series","into","a","standard","format",".","Provides","statistics",",","plotting","functions",",","and","ability","to","generate","future","dataframe","for","prediction",".","Attributes","--","--","--","--","--","df",":","`","pandas.DataFrame","`","Data","frame","containing","timestamp","and","value",",","with","standardized","column","names","for","internal","use","(","TIME_COL",",","VALUE_COL",")",".","Rows","are","sorted","by","time","index",",","and","missing","gaps","between","dates","are","filled","in","so","that","dates","are","spaced","at","regular","intervals",".","Values","are","adjusted","for","anomalies","according","to","``","anomaly_info","``",".","The","index","can","be","timezone","aware","(","but","TIME_COL","is","not",")",".","y",":","`","pandas.Series","`",",","dtype","float64","Value","of","time","series","to","forecast",".","time_stats",":","`","dict","`","Summary","statistics","about","the","timestamp","column",".","value_stats",":","`","dict","`","Summary","statistics","about","the","value","column",".","original_time_col",":","`","str","`","Name","of","time","column","in","original","input","data",".","original_value_col",":","`","str","`","Name","of","value","column","in","original","input","data",".","regressor_cols",":","`","list","`","[","`","str","`","]","A","list","of","regressor","columns","in","the","training","and","prediction","DataFrames",".","lagged_regressor_cols",":","`","list","`","[","`","str","`","]","A","list","of","additional","columns","needed","for","lagged","regressors","in","the","training","and","prediction","DataFrames",".","last_date_for_val",":","`","datetime.datetime","`","or","None",",","default","None","Date","or","timestamp","corresponding","to","last","non-null","value","in","``","df","[","original_value_col","]","``",".","last_date_for_reg",":","`","datetime.datetime","`","or","None",",","default","None","Date","or","timestamp","corresponding","to","last","non-null","value","in","``","df","[","regressor_cols","]","``",".","If","``","regressor_cols","``","is","None",",","``","last_date_for_reg","``","is","None",".","last_date_for_lag_reg",":","`","datetime.datetime","`","or","None",",","default","None","Date","or","timestamp","corresponding","to","last","non-null","value","in","``","df","[","lagged_regressor_cols","]","``",".","If","``","lagged_regressor_cols","``","is","None",",","``","last_date_for_lag_reg","``","is","None",".","train_end_date",":","`","datetime.datetime","`","Last","date","or","timestamp","in","``","fit_df","``",".","It","is","always","less","than","or","equal","to","minimum","non-null","values","of","``","last_date_for_val","``","and","``","last_date_for_reg","``",".","fit_cols",":","`","list","`","[","`","str","`","]","A","list","of","columns","used","in","the","training","and","prediction","DataFrames",".","fit_df",":","`","pandas.DataFrame","`","Data","frame","containing","timestamp","and","value",",","with","standardized","column","names","for","internal","use",".","Will","be","used","for","fitting","(","train",",","cv",",","backtest",")",".","fit_y",":","`","pandas.Series","`",",","dtype","float64","Value","of","time","series","for","fit_df",".","freq",":","`","str","`","timeseries","frequency",",","DateOffset","alias",",","e.g",".","{","'T","'","(","minute",")",",","'","H","'",",","D","'",",","'","W","'",",","'M","'","(","month","end",")",",","'MS","'","(","month","start",")",",","'","Y","'","(","year","end",")",",","'","Y","'","(","year","start",")","}","See","https",":","\/\/pandas.pydata.org\/pandas-docs\/stable\/user_guide\/timeseries.html","#","offset-aliases","anomaly_info",":","`","dict","`","or","`","list","`","[","`","dict","`","]","or","None",",","default","None","Anomaly","adjustment","info",".","Anomalies","in","``","df","``","are","corrected","before","any","forecasting","is","done",".","See","``","self.load_data","(",")","``","df_before_adjustment",":","`","pandas.DataFrame","`","or","None",",","default","None","``","self.df","``","before","adjustment","by","``","anomaly_info","``",".","Used","by","``","self.plot","(",")","``","to","show","the","adjustment","."]
docstr: Loads data to internal representation. Parses date column,
  sets timezone aware index.
  Checks for irregularities and raises an error if input is invalid.
  Adjusts for anomalies according to ``anomaly_info``.
  
  Parameters
  ----------
  df : `pandas.DataFrame`
      Input timeseries. A data frame which includes the timestamp column
      as well as the value column.
  time_col : `str`
      The column name in ``df`` representing time for the time series data.
      The time column can be anything that can be parsed by pandas DatetimeIndex.
  value_col: `str`
      The column name which has the value of interest to be forecasted.
  freq : `str` or None, default None
      Timeseries frequency, DateOffset alias, If None automatically inferred.
  date_format : `str` or None, default None
      strftime format to parse time column, eg ``%m/%d/%Y``.
      Note that ``%f`` will parse all the way up to nanoseconds.
      If None (recommended), inferred by `pandas.to_datetime`.
  tz : `str` or pytz.timezone object or None, default None
      Passed to `pandas.tz_localize` to localize the timestamp.
  train_end_date : `str` or `datetime.datetime` or None, default None
      Last date to use for fitting the model. Forecasts are generated after this date.
      If None, it is set to the minimum of ``self.last_date_for_val`` and
      ``self.last_date_for_reg``.
  regressor_cols: `list` [`str`] or None, default None
      A list of regressor columns used in the training and prediction DataFrames.
      If None, no regressor columns are used.
      Regressor columns that are unavailable in ``df`` are dropped.
  lagged_regressor_cols: `list` [`str`] or None, default None
      A list of additional columns needed for lagged regressors in the training and prediction DataFrames.
      This list can have overlap with ``regressor_cols``.
      If None, no additional columns are added to the DataFrame.
      Lagged regressor columns that are unavailable in ``df`` are dropped.
  anomaly_info : `dict` or `list` [`dict`] or None, default None
      Anomaly adjustment info. Anomalies in ``df``
      are corrected before any forecasting is done.
  
      If None, no adjustments are made.
  
      A dictionary containing the parameters to
      `~greykite.common.features.adjust_anomalous_data.adjust_anomalous_data`.
      See that function for details.
      The possible keys are:
  
          ``"value_col"`` : `str`
              The name of the column in ``df`` to adjust. You may adjust the value
              to forecast as well as any numeric regressors.
          ``"anomaly_df"`` : `pandas.DataFrame`
              Adjustments to correct the anomalies.
          ``"start_time_col"``: `str`, default START_TIME_COL
              Start date column in ``anomaly_df``.
          ``"end_time_col"``: `str`, default END_TIME_COL
              End date column in ``anomaly_df``.
          ``"adjustment_delta_col"``: `str` or None, default None
              Impact column in ``anomaly_df``.
          ``"filter_by_dict"``: `dict` or None, default None
              Used to filter ``anomaly_df`` to the relevant anomalies for
              the ``value_col`` in this dictionary.
              Key specifies the column name, value specifies the filter value.
          ``"filter_by_value_col""``: `str` or None, default None
              Adds ``{filter_by_value_col: value_col}`` to ``filter_by_dict``
              if not None, for the ``value_col`` in this dictionary.
          ``"adjustment_method"`` : `str` ("add" or "subtract"), default "add"
              How to make the adjustment, if ``adjustment_delta_col`` is provided.
  
      Accepts a list of such dictionaries to adjust multiple columns in ``df``.
  
  Returns
  -------
  self : Returns self.
      Sets ``self.df`` with standard column names,
      value adjusted for anomalies, and time gaps filled in,
      sorted by time index.
docstr_tok: ["Loads","data","to","internal","representation",".","Parses","date","column",",","sets","timezone","aware","index",".","Checks","for","irregularities","and","raises","an","error","if","input","is","invalid",".","Adjusts","for","anomalies","according","to","``","anomaly_info","``",".","Parameters","--","--","--","--","--","df",":","`","pandas.DataFrame","`","Input","timeseries",".","A","data","frame","which","includes","the","timestamp","column","as","well","as","the","value","column",".","time_col",":","`","str","`","The","column","name","in","``","df","``","representing","time","for","the","time","series","data",".","The","time","column","can","be","anything","that","can","be","parsed","by","pandas","DatetimeIndex",".","value_col",":","`","str","`","The","column","name","which","has","the","value","of","interest","to","be","forecasted",".","freq",":","`","str","`","or","None",",","default","None","Timeseries","frequency",",","DateOffset","alias",",","If","None","automatically","inferred",".","date_format",":","`","str","`","or","None",",","default","None","strftime","format","to","parse","time","column",",","eg","``","%","m\/","%","d\/","%","Y","``",".","Note","that","``","%","f","``","will","parse","all","the","way","up","to","nanoseconds",".","If","None","(","recommended",")",",","inferred","by","`","pandas.to_datetime","`",".","tz",":","`","str","`","or","pytz.timezone","object","or","None",",","default","None","Passed","to","`","pandas.tz_localize","`","to","localize","the","timestamp",".","train_end_date",":","`","str","`","or","`","datetime.datetime","`","or","None",",","default","None","Last","date","to","use","for","fitting","the","model",".","Forecasts","are","generated","after","this","date",".","If","None",",","it","is","set","to","the","minimum","of","``","self.last_date_for_val","``","and","``","self.last_date_for_reg","``",".","regressor_cols",":","`","list","`","[","`","str","`","]","or","None",",","default","None","A","list","of","regressor","columns","used","in","the","training","and","prediction","DataFrames",".","If","None",",","no","regressor","columns","are","used",".","Regressor","columns","that","are","unavailable","in","``","df","``","are","dropped",".","lagged_regressor_cols",":","`","list","`","[","`","str","`","]","or","None",",","default","None","A","list","of","additional","columns","needed","for","lagged","regressors","in","the","training","and","prediction","DataFrames",".","This","list","can","have","overlap","with","``","regressor_cols","``",".","If","None",",","no","additional","columns","are","added","to","the","DataFrame",".","Lagged","regressor","columns","that","are","unavailable","in","``","df","``","are","dropped",".","anomaly_info",":","`","dict","`","or","`","list","`","[","`","dict","`","]","or","None",",","default","None","Anomaly","adjustment","info",".","Anomalies","in","``","df","``","are","corrected","before","any","forecasting","is","done",".","If","None",",","no","adjustments","are","made",".","A","dictionary","containing","the","parameters","to","`","~greykite.common.features.adjust_anomalous_data.adjust_anomalous_data","`",".","See","that","function","for","details",".","The","possible","keys","are",":","``","``","value_col","''","``",":","`","str","`","The","name","of","the","column","in","``","df","``","to","adjust",".","You","may","adjust","the","value","to","forecast","as","well","as","any","numeric","regressors",".","``","``","anomaly_df","''","``",":","`","pandas.DataFrame","`","Adjustments","to","correct","the","anomalies",".","``","``","start_time_col","''","``",":","`","str","`",",","default","START_TIME_COL","Start","date","column","in","``","anomaly_df","``",".","``","``","end_time_col","''","``",":","`","str","`",",","default","END_TIME_COL","End","date","column","in","``","anomaly_df","``",".","``","``","adjustment_delta_col","''","``",":","`","str","`","or","None",",","default","None","Impact","column","in","``","anomaly_df","``",".","``","``","filter_by_dict","''","``",":","`","dict","`","or","None",",","default","None","Used","to","filter","``","anomaly_df","``","to","the","relevant","anomalies","for","the","``","value_col","``","in","this","dictionary",".","Key","specifies","the","column","name",",","value","specifies","the","filter","value",".","``","``","filter_by_value_col","''","''","``",":","`","str","`","or","None",",","default","None","Adds","``","{","filter_by_value_col",":","value_col","}","``","to","``","filter_by_dict","``","if","not","None",",","for","the","``","value_col","``","in","this","dictionary",".","``","``","adjustment_method","''","``",":","`","str","`","(","``","add","''","or","``","subtract","''",")",",","default","``","add","''","How","to","make","the","adjustment",",","if","``","adjustment_delta_col","``","is","provided",".","Accepts","a","list","of","such","dictionaries","to","adjust","multiple","columns","in","``","df","``",".","Returns","--","--","--","-","self",":","Returns","self",".","Sets","``","self.df","``","with","standard","column","names",",","value","adjusted","for","anomalies",",","and","time","gaps","filled","in",",","sorted","by","time","index","."]
code: def load_data(
      self,
      df: pd.DataFrame,
      time_col: str = TIME_COL,
      value_col: str = VALUE_COL,
      freq: Optional[str] = None,
      date_format: Optional[str] = None,
      tz: Optional[str] = None,
      train_end_date: Optional[Union[str, datetime]] = None,
      regressor_cols: Optional[List[str]] = None,
      lagged_regressor_cols: Optional[List[str]] = None,
      anomaly_info: Optional[Union[Dict, List[Dict]]] = None,
  ):
      """Loads data to internal representation. Parses date column,
      sets timezone aware index.
      Checks for irregularities and raises an error if input is invalid.
      Adjusts for anomalies according to ``anomaly_info``.
  
      Parameters
      ----------
      df : `pandas.DataFrame`
          Input timeseries. A data frame which includes the timestamp column
          as well as the value column.
      time_col : `str`
          The column name in ``df`` representing time for the time series data.
          The time column can be anything that can be parsed by pandas DatetimeIndex.
      value_col: `str`
          The column name which has the value of interest to be forecasted.
      freq : `str` or None, default None
          Timeseries frequency, DateOffset alias, If None automatically inferred.
      date_format : `str` or None, default None
          strftime format to parse time column, eg ``%m/%d/%Y``.
          Note that ``%f`` will parse all the way up to nanoseconds.
          If None (recommended), inferred by `pandas.to_datetime`.
      tz : `str` or pytz.timezone object or None, default None
          Passed to `pandas.tz_localize` to localize the timestamp.
      train_end_date : `str` or `datetime.datetime` or None, default None
          Last date to use for fitting the model. Forecasts are generated after this date.
          If None, it is set to the minimum of ``self.last_date_for_val`` and
          ``self.last_date_for_reg``.
      regressor_cols: `list` [`str`] or None, default None
          A list of regressor columns used in the training and prediction DataFrames.
          If None, no regressor columns are used.
          Regressor columns that are unavailable in ``df`` are dropped.
      lagged_regressor_cols: `list` [`str`] or None, default None
          A list of additional columns needed for lagged regressors in the training and prediction DataFrames.
          This list can have overlap with ``regressor_cols``.
          If None, no additional columns are added to the DataFrame.
          Lagged regressor columns that are unavailable in ``df`` are dropped.
      anomaly_info : `dict` or `list` [`dict`] or None, default None
          Anomaly adjustment info. Anomalies in ``df``
          are corrected before any forecasting is done.
  
          If None, no adjustments are made.
  
          A dictionary containing the parameters to
          `~greykite.common.features.adjust_anomalous_data.adjust_anomalous_data`.
          See that function for details.
          The possible keys are:
  
              ``"value_col"`` : `str`
                  The name of the column in ``df`` to adjust. You may adjust the value
                  to forecast as well as any numeric regressors.
              ``"anomaly_df"`` : `pandas.DataFrame`
                  Adjustments to correct the anomalies.
              ``"start_time_col"``: `str`, default START_TIME_COL
                  Start date column in ``anomaly_df``.
              ``"end_time_col"``: `str`, default END_TIME_COL
                  End date column in ``anomaly_df``.
              ``"adjustment_delta_col"``: `str` or None, default None
                  Impact column in ``anomaly_df``.
              ``"filter_by_dict"``: `dict` or None, default None
                  Used to filter ``anomaly_df`` to the relevant anomalies for
                  the ``value_col`` in this dictionary.
                  Key specifies the column name, value specifies the filter value.
              ``"filter_by_value_col""``: `str` or None, default None
                  Adds ``{filter_by_value_col: value_col}`` to ``filter_by_dict``
                  if not None, for the ``value_col`` in this dictionary.
              ``"adjustment_method"`` : `str` ("add" or "subtract"), default "add"
                  How to make the adjustment, if ``adjustment_delta_col`` is provided.
  
          Accepts a list of such dictionaries to adjust multiple columns in ``df``.
  
      Returns
      -------
      self : Returns self.
          Sets ``self.df`` with standard column names,
          value adjusted for anomalies, and time gaps filled in,
          sorted by time index.
      """
      self.original_time_col = time_col
      self.original_value_col = value_col
      self.anomaly_info = anomaly_info
  
      canonical_data_dict = get_canonical_data(
          df=df,
          time_col=time_col,
          value_col=value_col,
          freq=freq,
          date_format=date_format,
          tz=tz,
          train_end_date=pd.to_datetime(
              train_end_date, format=date_format
          ),
          regressor_cols=regressor_cols,
          lagged_regressor_cols=lagged_regressor_cols,
          anomaly_info=anomaly_info,
      )
      self.df = canonical_data_dict["df"]
      self.df_before_adjustment = canonical_data_dict[
          "df_before_adjustment"
      ]
      self.fit_df = canonical_data_dict["fit_df"]
      self.freq = canonical_data_dict["freq"]
      self.time_stats = canonical_data_dict["time_stats"]
      self.regressor_cols = canonical_data_dict["regressor_cols"]
      self.lagged_regressor_cols = canonical_data_dict[
          "lagged_regressor_cols"
      ]
      self.fit_cols = canonical_data_dict["fit_cols"]
      self.train_end_date = canonical_data_dict["train_end_date"]
      self.last_date_for_val = canonical_data_dict["last_date_for_val"]
      self.last_date_for_reg = canonical_data_dict["last_date_for_reg"]
      self.last_date_for_lag_reg = canonical_data_dict[
          "last_date_for_lag_reg"
      ]
  
      # y (possibly with null values) after gaps have been filled in and anomalies corrected
      self.y = self.df[VALUE_COL]
      self.fit_y = self.fit_df[VALUE_COL]
  
      # computes statistics of processed dataset
      self.describe_time_col()
      self.describe_value_col()  # compute value statistics
  
      log_message(
          f"last date for fit: {self.train_end_date}",
          LoggingLevelEnum.INFO,
      )
      log_message(
          f"last date for {self.original_value_col}: {self.last_date_for_val}",
          LoggingLevelEnum.INFO,
      )
      log_message(
          f"last date with any regressor: {self.last_date_for_reg}",
          LoggingLevelEnum.INFO,
      )
      log_message(
          f"columns available to use as regressors: {', '.join(self.regressor_cols)}",
          LoggingLevelEnum.INFO,
      )
      log_message(
          f"columns available to use as lagged regressors: {', '.join(self.lagged_regressor_cols)}",
          LoggingLevelEnum.INFO,
      )
  
      return self
  
imports: import warnings
  from datetime import datetime
  from functools import partial
  from typing import Dict
  from typing import List
  from typing import Optional
  from typing import Union
  import numpy
  import pandas
  from greykite.common.constants import TIME_COL
  from greykite.common.constants import VALUE_COL
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
  from greykite.common.time_properties import describe_timeseries
  from greykite.common.time_properties import get_canonical_data
  from greykite.common.viz.timeseries_plotting import add_groupby_column
  from greykite.common.viz.timeseries_plotting import flexible_grouping_evaluation
  from greykite.common.viz.timeseries_plotting import grouping_evaluation
  from greykite.common.viz.timeseries_plotting import plot_multivariate
  from greykite.common.viz.timeseries_plotting import plot_univariate
  from greykite.framework.constants import MEAN_COL_GROUP
  from greykite.framework.constants import OVERLAY_COL_GROUP
  from greykite.framework.constants import QUANTILE_COL_GROUP
label_desc: Use image node_id 2 for calling the UnivariateTimeSeries obj's underlying member method code with example usage: obj.load_data(df, time_col, value_col, freq, date_format, tz, train_end_date, regressor_cols, lagged_regressor_cols, anomaly_info) and returns: self