diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 63f0c9962fc..681fb1f070b 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -47,6 +47,12 @@ Bug fixes By `Thomas Coleman `_. - Proper plotting when passing :py:class:`~matplotlib.colors.BoundaryNorm` type argument in :py:meth:`DataArray.plot`. (:issue:`4061`, :issue:`7014`,:pull:`7553`) By `Jelmer Veenstra `_. +- Ensure the formatting of time encoding reference dates outside the range of + nanosecond-precision datetimes remains the same under pandas version 2.0.0 + (:issue:`7420`, :pull:`7441`). + By `Justus Magin `_ and + `Spencer Clark `_. + Documentation ~~~~~~~~~~~~~ diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index 4eae6302993..7f93706c74c 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -114,9 +114,9 @@ def calc_max_rows_last(max_rows: int) -> int: def format_timestamp(t): """Cast given object to a Timestamp and return a nicely formatted string""" - # Timestamp is only valid for 1678 to 2262 try: - datetime_str = str(pd.Timestamp(t)) + timestamp = pd.Timestamp(t) + datetime_str = timestamp.isoformat(sep=" ") except OutOfBoundsDatetime: datetime_str = str(t)