xarray.CFTimeIndex.to_datetimeindex#
- CFTimeIndex.to_datetimeindex(unsafe=False)[source]#
If possible, convert this index to a pandas.DatetimeIndex.
- Parameters:
unsafe (
bool
) โ Flag to turn off warning when converting from a CFTimeIndex with a non-standard calendar to a DatetimeIndex (defaultFalse
).- Returns:
- Raises:
ValueError โ If the CFTimeIndex contains dates that are not possible in the standard calendar or outside the nanosecond-precision range.
- Warns:
RuntimeWarning โ If converting from a non-standard calendar to a DatetimeIndex.
Warning
Note that for non-standard calendars, this will change the calendar type of the index. In that case the result of this method should be used with caution.
Examples
>>> times = xr.cftime_range("2000", periods=2, calendar="gregorian") >>> times CFTimeIndex([2000-01-01 00:00:00, 2000-01-02 00:00:00], dtype='object', length=2, calendar='standard', freq=None) >>> times.to_datetimeindex() DatetimeIndex(['2000-01-01', '2000-01-02'], dtype='datetime64[ns]', freq=None)