Skip to content

Commit 84607c3

Browse files
spencerkclarkdcheriankeewispre-commit-ci[bot]
authored
Preserve formatting of reference time units under pandas 2.0.0 (#7441)
* [test-upstream] Preserve formatting of reference time units Changes in pandas 2.0.0 interfere with the way we expect some times to be formatted. * Use strftime to force expected date format Co-authored-by: Justus Magin <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [test-upstream] Preserve formatting of reference time units Changes in pandas 2.0.0 interfere with the way we expect some times to be formatted. * Use strftime to force expected date format Co-authored-by: Justus Magin <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [test-upstream] Remove old comment and move what's new entry to latest version * [test-upstream] remove old comment and move what's new entry * Update xarray/core/formatting.py * Use isoformat() now that pandas zero-pads years Co-authored-by: Justus Magin <[email protected]> * [test-upstream] update what's new * replace the `isoformat` separator with `" "` [test-upstream] * use the `sep` parameter to `isoformat` instead Co-authored-by: Spencer Clark <[email protected]> * Update doc/whats-new.rst --------- Co-authored-by: Deepak Cherian <[email protected]> Co-authored-by: Justus Magin <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Justus Magin <[email protected]>
1 parent 1c81162 commit 84607c3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

doc/whats-new.rst

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ Bug fixes
4747
By `Thomas Coleman <https://github.com/ColemanTom>`_.
4848
- Proper plotting when passing :py:class:`~matplotlib.colors.BoundaryNorm` type argument in :py:meth:`DataArray.plot`. (:issue:`4061`, :issue:`7014`,:pull:`7553`)
4949
By `Jelmer Veenstra <https://github.com/veenstrajelmer>`_.
50+
- Ensure the formatting of time encoding reference dates outside the range of
51+
nanosecond-precision datetimes remains the same under pandas version 2.0.0
52+
(:issue:`7420`, :pull:`7441`).
53+
By `Justus Magin <https://github.com/keewis>`_ and
54+
`Spencer Clark <https://github.com/spencerkclark>`_.
55+
5056

5157
Documentation
5258
~~~~~~~~~~~~~

xarray/core/formatting.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ def calc_max_rows_last(max_rows: int) -> int:
114114

115115
def format_timestamp(t):
116116
"""Cast given object to a Timestamp and return a nicely formatted string"""
117-
# Timestamp is only valid for 1678 to 2262
118117
try:
119-
datetime_str = str(pd.Timestamp(t))
118+
timestamp = pd.Timestamp(t)
119+
datetime_str = timestamp.isoformat(sep=" ")
120120
except OutOfBoundsDatetime:
121121
datetime_str = str(t)
122122

0 commit comments

Comments
 (0)