code: def date_freq_handler(df):
      """
      This returns a column definition handler which returns a series based on the specs from the front-end.
      Column definitions can be a column name 'Col1' or a column name with a frequency 'Col1|M' for
      columns which are of type datetime.
  
      :Example:
          Col1 -> returns series for Col1
          Col1|M -> returns series for Col1 in monthly format with name 'Col1|M'
  
      :param df: dataframe whose data needs to be checked
      :type df: :class:`pandas:pandas.DataFrame`
      :return: handler function
      :rtype: func
      """
      dtypes = get_dtypes(df)
      orig_idx = df.index
  
      def _handler(col_def):
          col_def_segs = col_def.split(CHART_JOINER_CHAR)
          if (
              len(col_def_segs) > 1
              and classify_type(dtypes[col_def_segs[0]]) == "D"
          ):
              col, freq = col_def_segs
              if freq == "WD":
                  code = "df.set_index('{col}').index.dayofweek.values"
                  freq_grp = df.set_index(col).index.dayofweek.values
              elif freq == "H2":
                  code = "df.set_index('{col}').index.hour.values"
                  freq_grp = df.set_index(col).index.hour.values
              else:
                  code = "df.set_index('{col}').index.to_period('{freq}').to_timestamp(how='end').values"
                  freq_grp = (
                      df.set_index(col)
                      .index.to_period(freq)
                      .to_timestamp(how="end")
                      .values
                  )
              code = (
                  "\tpd.Series("
                  + code
                  + ", index=df.index, name='{col_def}'),"
              )
              freq_grp = pd.Series(
                  freq_grp, index=orig_idx, name=col_def
              )
              return freq_grp, code.format(
                  col=col, freq=freq, col_def=col_def
              )
          else:
              return df[col_def], "\tdf['{col_def}'],".format(
                  col_def=col_def
              )
  
      return _handler
  
imports: import copy
  import numpy
  import pandas
  import dtale.global_state
  import dtale.pandas_util
  from dtale.column_analysis import handle_cleaners
  from dtale.constants import CHART_JOINER_CHAR
  from dtale.query import build_col_key, run_query
  from dtale.utils import ChartBuildingError, build_formatters, classify_type, find_dtype, find_dtype_formatter, flatten_lists, get_dtypes, json_int, make_list, triple_quote
label_desc: Use image node_id 4 for calling a global function with example usage: date_freq_handler(df) and returns: _handler, freq_grp,  code, df,  str