code: def filter_date(
      df: pd.DataFrame,
      column_name: Hashable,
      start_date: Optional[dt.date] = None,
      end_date: Optional[dt.date] = None,
      years: Optional[List] = None,
      months: Optional[List] = None,
      days: Optional[List] = None,
      column_date_options: Optional[Dict] = None,
      format: Optional[str] = None,  # skipcq: PYL-W0622
  ) -> pd.DataFrame:
      """Filter a date-based column based on certain criteria.
  
      This method does not mutate the original DataFrame.
  
      Dates may be finicky and this function builds on top of the *magic* from
      the pandas `to_datetime` function that is able to parse dates well.
  
      Additional options to parse the date type of your column may be found at
      the official pandas [documentation][datetime].
  
      [datetime]: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html
  
      Examples:
          >>> import pandas as pd
          >>> import janitor
          >>> df = pd.DataFrame({
          ...     "a": range(5, 9),
          ...     "dt": ["2021-11-12", "2021-12-15", "2022-01-03", "2022-01-09"],
          ... })
          >>> df
             a          dt
          0  5  2021-11-12
          1  6  2021-12-15
          2  7  2022-01-03
          3  8  2022-01-09
          >>> df.filter_date("dt", start_date="2021-12-01", end_date="2022-01-05")
             a         dt
          1  6 2021-12-15
          2  7 2022-01-03
          >>> df.filter_date("dt", years=[2021], months=[12])
             a         dt
          1  6 2021-12-15
  
      !!!note
  
          This method will cast your column to a Timestamp!
  
      !!!note
  
          This only affects the format of the `start_date` and `end_date`
          parameters. If there's an issue with the format of the DataFrame being
          parsed, you would pass `{'format': your_format}` to `column_date_options`.
  
      Args:
          df: The dataframe to filter on.
          column_name: The column which to apply the fraction transformation.
          start_date: The beginning date to use to filter the DataFrame.
          end_date: The end date to use to filter the DataFrame.
          years: The years to use to filter the DataFrame.
          months: The months to use to filter the DataFrame.
          days: The days to use to filter the DataFrame.
          column_date_options: Special options to use when parsing the date
              column in the original DataFrame. The options may be found at the
              official Pandas documentation.
          format: If you're using a format for `start_date` or `end_date`
              that is not recognized natively by pandas' `to_datetime` function, you
              may supply the format yourself. Python date and time formats may be
              found [here](http://strftime.org/).
  
      Returns:
          A filtered pandas DataFrame.
      """  # noqa: E501
  
      def _date_filter_conditions(conditions):
          """Taken from: https://stackoverflow.com/a/13616382."""
          return reduce(np.logical_and, conditions)
  
      if column_date_options is None:
          column_date_options = {}
      df[column_name] = pd.to_datetime(
          df[column_name], **column_date_options
      )
  
      _filter_list = []
  
      if start_date:
          start_date = pd.to_datetime(start_date, format=format)
          _filter_list.append(df[column_name] >= start_date)
  
      if end_date:
          end_date = pd.to_datetime(end_date, format=format)
          _filter_list.append(df[column_name] <= end_date)
  
      if years:
          _filter_list.append(df[column_name].dt.year.isin(years))
  
      if months:
          _filter_list.append(df[column_name].dt.month.isin(months))
  
      if days:
          _filter_list.append(df[column_name].dt.day.isin(days))
  
      if start_date and end_date and start_date > end_date:
          warnings.warn(
              f"Your start date of {start_date} is after your end date of "
              f"{end_date}. Is this intended?"
          )
  
      return df.loc[_date_filter_conditions(_filter_list), :]
  
file_path: pyjanitor/janitor/functions/filter.py
imports: import datetime
  import warnings
  from functools import reduce
  from typing import Any, Dict, Hashable, Iterable, List, Optional
  import numpy
  import pandas
  import pandas_flavor
  from janitor.utils import deprecated_alias, find_stack_level, refactored_function
label_desc: Use image node_id 3 for calling a global function with example usage: filter_date(df, column_name, start_date, end_date, years, months, days, column_date_options, format) and returns: df, reduce