code: def sort_timestamps_monotonically(
      df: pd.DataFrame,
      direction: str = "increasing",
      strict: bool = False,
  ) -> pd.DataFrame:
      """Sort DataFrame such that index is monotonic.
  
      If timestamps are monotonic, this function will return
      the DataFrame unmodified. If timestamps are not monotonic,
      then the function will sort the DataFrame.
  
      Examples:
          Functional usage
  
          >>> import pandas as pd
          >>> import janitor.timeseries
          >>> df = janitor.timeseries.sort_timestamps_monotonically(
          ...     df=pd.DataFrame(...),
          ...     direction="increasing",
          ... )  # doctest: +SKIP
  
          Method chaining example:
  
          >>> import pandas as pd
          >>> import janitor.timeseries
          >>> df = (
          ...     pd.DataFrame(...)
          ...     .sort_timestamps_monotonically(direction="increasing")
          ... )  # doctest: +SKIP
  
      Args:
          df: DataFrame which needs to be tested for monotonicity.
          direction: Type of monotonicity desired.
              Acceptable arguments are `'increasing'` or `'decreasing'`.
          strict: Flag to enable/disable strict monotonicity.
              If set to `True`, will remove duplicates in the index
              by retaining first occurrence of value in index.
              If set to `False`, will not test for duplicates in the index.
  
      Returns:
          DataFrame that has monotonically increasing (or decreasing)
              timestamps.
      """
      # Check all the inputs are the correct data type
      check("df", df, [pd.DataFrame])
      check("direction", direction, [str])
      check("strict", strict, [bool])
  
      # Remove duplicates if requested
      if strict:
          df = df[~df.index.duplicated(keep="first")]
  
      # Sort timestamps
      if direction == "increasing":
          df = df.sort_index()
      else:
          df = df.sort_index(ascending=False)
  
      # Return the DataFrame
      return df
  
file_path: pyjanitor/janitor/timeseries.py
imports: import itertools
  from typing import Dict, Union
  import pandas
  import pandas_flavor
  from .errors import JanitorError
  from .utils import check
label_desc: Use image node_id 3 for calling a global function with example usage: sort_timestamps_monotonically(df, direction, strict) and returns: df