🍾 Xarray is now 10 years old! 🎉

xarray.date_range

Contents

xarray.date_range#

xarray.date_range(start=None, end=None, periods=None, freq=None, tz=None, normalize=False, name=None, closed=_NoDefault.no_default, inclusive=None, calendar='standard', use_cftime=None)[source]#

Return a fixed frequency datetime index.

The type (xarray.CFTimeIndex or pandas.DatetimeIndex) of the returned index depends on the requested calendar and on use_cftime.

Parameters:
  • start (str or datetime-like, optional) – Left bound for generating dates.

  • end (str or datetime-like, optional) – Right bound for generating dates.

  • periods (int, optional) – Number of periods to generate.

  • freq (str or None, default: "D") – Frequency strings can have multiples, e.g. “5h” and negative values, e.g. “-1D”.

  • tz (str or tzinfo, optional) – Time zone name for returning localized DatetimeIndex, for example ‘Asia/Hong_Kong’. By default, the resulting DatetimeIndex is timezone-naive. Only valid with pandas DatetimeIndex.

  • normalize (bool, default: False) – Normalize start/end dates to midnight before generating date range.

  • name (str, default: None) – Name of the resulting index

  • closed ({None, "left", "right"}, default: "NO_DEFAULT") – Make the interval closed with respect to the given frequency to the “left”, “right”, or both sides (None).

    Deprecated since version 2023.02.0: Following pandas, the closed parameter is deprecated in favor of the inclusive parameter, and will be removed in a future version of xarray.

  • inclusive ({None, "both", "neither", "left", "right"}, default: None) – Include boundaries; whether to set each bound as closed or open.

    New in version 2023.02.0.

  • calendar (str, default: "standard") – Calendar type for the datetimes.

  • use_cftime (boolean, optional) – If True, always return a CFTimeIndex. If False, return a pd.DatetimeIndex if possible or raise a ValueError. If None (default), return a pd.DatetimeIndex if possible, otherwise return a CFTimeIndex. Defaults to False if tz is not None.

Returns:

CFTimeIndex or pd.DatetimeIndex