def last(self, offset: Union[(str, DateOffset)]) -> 'DataFrame':
    "\n        Select final periods of time series data based on a date offset.\n\n        When having a DataFrame with dates as index, this function can\n        select the last few rows based on a date offset.\n\n        Parameters\n        ----------\n        offset : str or DateOffset\n            The offset length of the data that will be selected. For instance,\n            '3D' will display all the rows having their index within the last 3 days.\n\n        Returns\n        -------\n        DataFrame\n            A subset of the caller.\n\n        Raises\n        ------\n        TypeError\n            If the index is not a :class:`DatetimeIndex`\n\n        Examples\n        --------\n\n        >>> index = pd.date_range('2018-04-09', periods=4, freq='2D')\n        >>> psdf = ps.DataFrame({'A': [1, 2, 3, 4]}, index=index)\n        >>> psdf\n                    A\n        2018-04-09  1\n        2018-04-11  2\n        2018-04-13  3\n        2018-04-15  4\n\n        Get the rows for the last 3 days:\n\n        >>> psdf.last('3D')\n                    A\n        2018-04-13  3\n        2018-04-15  4\n\n        Notice the data for 3 last calendar days were returned, not the last\n        3 observed days in the dataset, and therefore data for 2018-04-11 was\n        not returned.\n        "
    if (not isinstance(self.index, ps.DatetimeIndex)):
        raise TypeError("'last' only supports a DatetimeIndex")
    offset_: Optional[DateOffset] = to_offset(offset)
    assert (offset_ is not None)
    from_date = (cast(datetime.datetime, self.index.max()) - offset_)
    return cast(DataFrame, self.loc[from_date:])
Select final periods of time series data based on a date offset.

When having a DataFrame with dates as index, this function can
select the last few rows based on a date offset.

Parameters
----------
offset : str or DateOffset
    The offset length of the data that will be selected. For instance,
    '3D' will display all the rows having their index within the last 3 days.

Returns
-------
DataFrame
    A subset of the caller.

Raises
------
TypeError
    If the index is not a :class:`DatetimeIndex`

Examples
--------

>>> index = pd.date_range('2018-04-09', periods=4, freq='2D')
>>> psdf = ps.DataFrame({'A': [1, 2, 3, 4]}, index=index)
>>> psdf
            A
2018-04-09  1
2018-04-11  2
2018-04-13  3
2018-04-15  4

Get the rows for the last 3 days:

>>> psdf.last('3D')
            A
2018-04-13  3
2018-04-15  4

Notice the data for 3 last calendar days were returned, not the last
3 observed days in the dataset, and therefore data for 2018-04-11 was
not returned.
def last(self, offset: Union[(str, DateOffset)]) -> 'DataFrame':
    "\n        Select final periods of time series data based on a date offset.\n\n        When having a DataFrame with dates as index, this function can\n        select the last few rows based on a date offset.\n\n        Parameters\n        ----------\n        offset : str or DateOffset\n            The offset length of the data that will be selected. For instance,\n            '3D' will display all the rows having their index within the last 3 days.\n\n        Returns\n        -------\n        DataFrame\n            A subset of the caller.\n\n        Raises\n        ------\n        TypeError\n            If the index is not a :class:`DatetimeIndex`\n\n        Examples\n        --------\n\n        >>> index = pd.date_range('2018-04-09', periods=4, freq='2D')\n        >>> psdf = ps.DataFrame({'A': [1, 2, 3, 4]}, index=index)\n        >>> psdf\n                    A\n        2018-04-09  1\n        2018-04-11  2\n        2018-04-13  3\n        2018-04-15  4\n\n        Get the rows for the last 3 days:\n\n        >>> psdf.last('3D')\n                    A\n        2018-04-13  3\n        2018-04-15  4\n\n        Notice the data for 3 last calendar days were returned, not the last\n        3 observed days in the dataset, and therefore data for 2018-04-11 was\n        not returned.\n        "
    if (not isinstance(self.index, ps.DatetimeIndex)):
        raise TypeError("'last' only supports a DatetimeIndex")
    offset_: Optional[DateOffset] = to_offset(offset)
    assert (offset_ is not None)
    from_date = (cast(datetime.datetime, self.index.max()) - offset_)
    return cast(DataFrame, self.loc[from_date:])