Skip to content

Commit c9c1c6d

Browse files
spencerkclarkdcheriankeewisIllviljan
authored
Continue to use nanosecond-precision Timestamps in precision-sensitive areas (#7731)
* [test-upstream] use nanosecond-precision timestamps for now * [test-upstream] allow kwargs to be passed to nanosecond_precision_timestamp * unpin `pandas` * Add type hint for nanosecond_precision_timestamp Co-authored-by: Illviljan <[email protected]> * Add one more TODO comment * Remove deleted attributes in CFTimeIndex documentation * Add a what's new entry * Remove one more attribute from api-hidden.rst * Silence conversion warnings in tests * Silence more conversion warnings --------- Co-authored-by: Deepak Cherian <[email protected]> Co-authored-by: Justus Magin <[email protected]> Co-authored-by: Illviljan <[email protected]>
1 parent 13a47fd commit c9c1c6d

22 files changed

+144
-75
lines changed

ci/requirements/all-but-dask.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies:
2525
- numbagg
2626
- numpy<1.24
2727
- packaging
28-
- pandas<2
28+
- pandas
2929
- pint
3030
- pip
3131
- pseudonetcdf

ci/requirements/doc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies:
1919
- numba
2020
- numpy>=1.21,<1.24
2121
- packaging>=21.3
22-
- pandas>=1.4,<2
22+
- pandas>=1.4
2323
- pooch
2424
- pip
2525
- pre-commit

ci/requirements/environment-py311.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dependencies:
2727
- numexpr
2828
- numpy
2929
- packaging
30-
- pandas<2
30+
- pandas
3131
- pint
3232
- pip
3333
- pooch

ci/requirements/environment-windows-py311.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies:
2424
# - numbagg
2525
- numpy
2626
- packaging
27-
- pandas<2
27+
- pandas
2828
- pint
2929
- pip
3030
- pre-commit

ci/requirements/environment-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies:
2424
- numbagg
2525
- numpy<1.24
2626
- packaging
27-
- pandas<2
27+
- pandas
2828
- pint
2929
- pip
3030
- pre-commit

ci/requirements/environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dependencies:
2727
- numexpr
2828
- numpy<1.24
2929
- packaging
30-
- pandas<2
30+
- pandas
3131
- pint
3232
- pip
3333
- pooch

doc/api-hidden.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,8 @@
375375
CFTimeIndex.is_floating
376376
CFTimeIndex.is_integer
377377
CFTimeIndex.is_interval
378-
CFTimeIndex.is_mixed
379378
CFTimeIndex.is_numeric
380379
CFTimeIndex.is_object
381-
CFTimeIndex.is_type_compatible
382380
CFTimeIndex.isin
383381
CFTimeIndex.isna
384382
CFTimeIndex.isnull
@@ -399,7 +397,6 @@
399397
CFTimeIndex.round
400398
CFTimeIndex.searchsorted
401399
CFTimeIndex.set_names
402-
CFTimeIndex.set_value
403400
CFTimeIndex.shift
404401
CFTimeIndex.slice_indexer
405402
CFTimeIndex.slice_locs
@@ -413,7 +410,6 @@
413410
CFTimeIndex.to_flat_index
414411
CFTimeIndex.to_frame
415412
CFTimeIndex.to_list
416-
CFTimeIndex.to_native_types
417413
CFTimeIndex.to_numpy
418414
CFTimeIndex.to_series
419415
CFTimeIndex.tolist
@@ -438,8 +434,6 @@
438434
CFTimeIndex.hasnans
439435
CFTimeIndex.hour
440436
CFTimeIndex.inferred_type
441-
CFTimeIndex.is_all_dates
442-
CFTimeIndex.is_monotonic
443437
CFTimeIndex.is_monotonic_increasing
444438
CFTimeIndex.is_monotonic_decreasing
445439
CFTimeIndex.is_unique

doc/user-guide/weather-climate.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ CF-compliant coordinate variables
5757

5858
.. _CFTimeIndex:
5959

60-
Non-standard calendars and dates outside the Timestamp-valid range
61-
------------------------------------------------------------------
60+
Non-standard calendars and dates outside the nanosecond-precision range
61+
-----------------------------------------------------------------------
6262

6363
Through the standalone ``cftime`` library and a custom subclass of
6464
:py:class:`pandas.Index`, xarray supports a subset of the indexing
6565
functionality enabled through the standard :py:class:`pandas.DatetimeIndex` for
6666
dates from non-standard calendars commonly used in climate science or dates
67-
using a standard calendar, but outside the `Timestamp-valid range`_
67+
using a standard calendar, but outside the `nanosecond-precision range`_
6868
(approximately between years 1678 and 2262).
6969

7070
.. note::
@@ -75,13 +75,19 @@ using a standard calendar, but outside the `Timestamp-valid range`_
7575
any of the following are true:
7676

7777
- The dates are from a non-standard calendar
78-
- Any dates are outside the Timestamp-valid range.
78+
- Any dates are outside the nanosecond-precision range.
7979

8080
Otherwise pandas-compatible dates from a standard calendar will be
8181
represented with the ``np.datetime64[ns]`` data type, enabling the use of a
8282
:py:class:`pandas.DatetimeIndex` or arrays with dtype ``np.datetime64[ns]``
8383
and their full set of associated features.
8484

85+
As of pandas version 2.0.0, pandas supports non-nanosecond precision datetime
86+
values. For the time being, xarray still automatically casts datetime values
87+
to nanosecond-precision for backwards compatibility with older pandas
88+
versions; however, this is something we would like to relax going forward.
89+
See :issue:`7493` for more discussion.
90+
8591
For example, you can create a DataArray indexed by a time
8692
coordinate with dates from a no-leap calendar and a
8793
:py:class:`~xarray.CFTimeIndex` will automatically be used:
@@ -235,6 +241,6 @@ For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
235241
236242
da.resample(time="81T", closed="right", label="right", offset="3T").mean()
237243
238-
.. _Timestamp-valid range: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timestamp-limitations
244+
.. _nanosecond-precision range: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timestamp-limitations
239245
.. _ISO 8601 standard: https://en.wikipedia.org/wiki/ISO_8601
240246
.. _partial datetime string indexing: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#partial-string-indexing

doc/whats-new.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ Internal Changes
8888
- Added a config.yml file with messages for the welcome bot when a Github user creates their first ever issue or pull request or has their first PR merged. (:issue:`7685`, :pull:`7685`)
8989
By `Nishtha P <https://github.com/nishthap981>`_.
9090

91+
- Ensure that only nanosecond-precision :py:class:`pd.Timestamp` objects
92+
continue to be used internally under pandas version 2.0.0. This is mainly to
93+
ease the transition to this latest version of pandas. It should be relaxed
94+
when addressing :issue:`7493`. By `Spencer Clark
95+
<https://github.com/spencerkclark>`_ (:issue:`7707`, :pull:`7731`).
96+
9197
.. _whats-new.2023.03.0:
9298

9399
v2023.03.0 (March 22, 2023)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ include_package_data = True
7676
python_requires = >=3.9
7777
install_requires =
7878
numpy >= 1.21 # recommended to use >= 1.22 for full quantile method support
79-
pandas >= 1.4, <2
79+
pandas >= 1.4
8080
packaging >= 21.3
8181

8282
[options.extras_require]

0 commit comments

Comments
 (0)