Skip to content

Commit 2c2e7dc

Browse files
committed
Merge remote-tracking branch 'upstream/main' into groupby-aggs-using-numpy-groupies
* upstream/main: (23 commits) Small typing fix (pydata#6159) Drop support for python 3.7 (pydata#5892) _season_from_months can now handle np.nan (pydata#5876) Use base ImportError not MoudleNotFoundError when trying to see if the (pydata#6154) Remove numpy from mypy pre-commit (pydata#6151) Change concat dims to be Hashable (pydata#6121) Bump pypa/gh-action-pypi-publish from 1.4.2 to 1.5.0 (pydata#6147) Remove registration of pandas datetime converter in plotting (pydata#6109) Remove pd.Panel checks (pydata#6145) Remove paren from DataArray.from_dict docstring (pydata#6140) Revert "Deprecate bool(ds) (pydata#6126)" (pydata#6141) remove paren from data that is fed to 1D DataArray (pydata#6139) Check for just `...`, rather than `[...]` in `da.stack` (pydata#6132) DOC: Add "auto" to dataarray `chunk` method (pydata#6068) TST: check datetime converter is Matplotlibs (pydata#6128) New algorithm for forward filling (pydata#6118) Limit and format number of displayed dimensions in repr (pydata#5662) Add labels to dataset diagram (pydata#6076) Deprecate bool(ds) (pydata#6126) Revert "disable pytest-xdist (to check CI failure)" (pydata#6127) ...
2 parents 41e43fe + 18703ba commit 2c2e7dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1921
-244
lines changed

.github/workflows/ci-additional.yaml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ jobs:
4040
os: ["ubuntu-latest"]
4141
env:
4242
[
43-
"py37-bare-minimum",
44-
"py37-min-all-deps",
45-
"py38-all-but-dask",
46-
"py38-flaky",
43+
# Minimum python version:
44+
"py38-bare-minimum",
45+
"py38-min-all-deps",
46+
47+
# Latest python version:
48+
"py39-all-but-dask",
49+
"py39-flaky",
4750
]
4851
steps:
4952
- uses: actions/checkout@v2
@@ -52,7 +55,7 @@ jobs:
5255

5356
- name: Set environment variables
5457
run: |
55-
if [[ ${{ matrix.env }} == "py38-flaky" ]] ;
58+
if [[ ${{ matrix.env }} == "py39-flaky" ]] ;
5659
then
5760
echo "CONDA_ENV_FILE=ci/requirements/environment.yml" >> $GITHUB_ENV
5861
echo "PYTEST_EXTRA_FLAGS=--run-flaky --run-network-tests" >> $GITHUB_ENV
@@ -75,7 +78,7 @@ jobs:
7578
mamba-version: "*"
7679
activate-environment: xarray-tests
7780
auto-update-conda: false
78-
python-version: 3.8
81+
python-version: 3.9
7982
use-only-tar-bz2: true
8083

8184
- name: Install conda dependencies
@@ -96,7 +99,7 @@ jobs:
9699
python -c "import xarray"
97100
- name: Run tests
98101
run: |
99-
python -m pytest \
102+
python -m pytest -n 4 \
100103
--cov=xarray \
101104
--cov-report=xml \
102105
$PYTEST_EXTRA_FLAGS
@@ -128,7 +131,7 @@ jobs:
128131
mamba-version: "*"
129132
activate-environment: xarray-tests
130133
auto-update-conda: false
131-
python-version: "3.8"
134+
python-version: "3.9"
132135

133136
- name: Install conda dependencies
134137
run: |
@@ -164,10 +167,10 @@ jobs:
164167
channel-priority: strict
165168
mamba-version: "*"
166169
auto-update-conda: false
167-
python-version: "3.8"
170+
python-version: "3.9"
168171

169172
- name: minimum versions policy
170173
run: |
171174
mamba install -y pyyaml conda python-dateutil
172-
python ci/min_deps_check.py ci/requirements/py37-bare-minimum.yml
173-
python ci/min_deps_check.py ci/requirements/py37-min-all-deps.yml
175+
python ci/min_deps_check.py ci/requirements/py38-bare-minimum.yml
176+
python ci/min_deps_check.py ci/requirements/py38-min-all-deps.yml

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
matrix:
3939
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
4040
# Bookend python versions
41-
python-version: ["3.7", "3.9"]
41+
python-version: ["3.8", "3.9"]
4242
steps:
4343
- uses: actions/checkout@v2
4444
with:
@@ -87,7 +87,7 @@ jobs:
8787
run: |
8888
python -c "import xarray"
8989
- name: Run tests
90-
run: python -m pytest
90+
run: python -m pytest -n 4
9191
--cov=xarray
9292
--cov-report=xml
9393
--junitxml=pytest.xml

.github/workflows/pypi-release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
ls -ltrh dist
6565
- name: Publish package to TestPyPI
6666
if: github.event_name == 'push'
67-
uses: pypa/gh-action-pypi-publish@v1.4.2
67+
uses: pypa/gh-action-pypi-publish@v1.5.0
6868
with:
6969
user: __token__
7070
password: ${{ secrets.TESTPYPI_TOKEN }}
@@ -89,7 +89,7 @@ jobs:
8989
name: releases
9090
path: dist
9191
- name: Publish package to PyPI
92-
uses: pypa/gh-action-pypi-publish@v1.4.2
92+
uses: pypa/gh-action-pypi-publish@v1.5.0
9393
with:
9494
user: __token__
9595
password: ${{ secrets.PYPI_TOKEN }}

.pre-commit-config.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ repos:
3232
# - id: velin
3333
# args: ["--write", "--compact"]
3434
- repo: https://github.com/pre-commit/mirrors-mypy
35-
rev: v0.930
35+
rev: v0.931
3636
hooks:
3737
- id: mypy
3838
# `properies` & `asv_bench` are copied from setup.cfg.
@@ -45,8 +45,6 @@ repos:
4545
types-PyYAML,
4646
types-pytz,
4747
typing-extensions==3.10.0.0,
48-
# Dependencies that are typed
49-
numpy,
5048
]
5149
# run this occasionally, ref discussion https://github.com/pydata/xarray/pull/3194
5250
# - repo: https://github.com/asottile/pyupgrade

ci/requirements/environment-windows.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ dependencies:
3737
- rasterio
3838
- scipy
3939
- seaborn
40-
- setuptools
4140
- sparse
4241
- toolz
4342
- typing_extensions

ci/requirements/environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ dependencies:
4141
- rasterio
4242
- scipy
4343
- seaborn
44-
- setuptools
4544
- sparse
4645
- toolz
4746
- typing_extensions

ci/requirements/py37-bare-minimum.yml renamed to ci/requirements/py38-bare-minimum.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ channels:
33
- conda-forge
44
- nodefaults
55
dependencies:
6-
- python=3.7
6+
- python=3.8
77
- coveralls
88
- pip
99
- pytest
@@ -12,5 +12,3 @@ dependencies:
1212
- pytest-xdist
1313
- numpy=1.18
1414
- pandas=1.1
15-
- typing_extensions=3.7
16-
- importlib-metadata=2.0

ci/requirements/py37-min-all-deps.yml renamed to ci/requirements/py38-min-all-deps.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies:
77
# Run ci/min_deps_check.py to verify that this file respects the policy.
88
# When upgrading python, numpy, or pandas, must also change
99
# doc/installing.rst and setup.py.
10-
- python=3.7
10+
- python=3.8
1111
- boto3=1.13
1212
- bottleneck=1.3
1313
# cartopy 0.18 conflicts with pynio
@@ -24,7 +24,6 @@ dependencies:
2424
- hdf5=1.10
2525
- hypothesis
2626
- iris=2.4
27-
- importlib-metadata=2.0
2827
- lxml=4.6 # Optional dep of pydap
2928
- matplotlib-base=3.3
3029
- nc-time-axis=1.2

ci/requirements/py38-all-but-dask.yml renamed to ci/requirements/py39-all-but-dask.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ channels:
33
- conda-forge
44
- nodefaults
55
dependencies:
6-
- python=3.8
6+
- python=3.9
77
- black
88
- aiobotocore
99
- boto3
@@ -38,7 +38,6 @@ dependencies:
3838
- rasterio
3939
- scipy
4040
- seaborn
41-
- setuptools
4241
- sparse
4342
- toolz
4443
- typing_extensions

doc/_static/dataset-diagram.png

-10.5 KB
Loading

doc/api-hidden.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
core.accessor_dt.DatetimeAccessor.floor
7878
core.accessor_dt.DatetimeAccessor.round
7979
core.accessor_dt.DatetimeAccessor.strftime
80+
core.accessor_dt.DatetimeAccessor.calendar
8081
core.accessor_dt.DatetimeAccessor.date
8182
core.accessor_dt.DatetimeAccessor.day
8283
core.accessor_dt.DatetimeAccessor.dayofweek

doc/api.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ Dataset contents
109109
Dataset.drop_dims
110110
Dataset.set_coords
111111
Dataset.reset_coords
112+
Dataset.convert_calendar
113+
Dataset.interp_calendar
112114
Dataset.get_index
113115

114116
Comparisons
@@ -308,6 +310,8 @@ DataArray contents
308310
DataArray.drop_duplicates
309311
DataArray.reset_coords
310312
DataArray.copy
313+
DataArray.convert_calendar
314+
DataArray.interp_calendar
311315
DataArray.get_index
312316
DataArray.astype
313317
DataArray.item
@@ -526,6 +530,7 @@ Datetimelike properties
526530
DataArray.dt.season
527531
DataArray.dt.time
528532
DataArray.dt.date
533+
DataArray.dt.calendar
529534
DataArray.dt.is_month_start
530535
DataArray.dt.is_month_end
531536
DataArray.dt.is_quarter_end
@@ -1064,6 +1069,8 @@ Creating custom indexes
10641069
:toctree: generated/
10651070

10661071
cftime_range
1072+
date_range
1073+
date_range_like
10671074

10681075
Faceting
10691076
--------

doc/getting-started-guide/installing.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ Installation
66
Required dependencies
77
---------------------
88

9-
- Python (3.7 or later)
10-
- `importlib_metadata <https://importlib_metadata.readthedocs.io/>`__ (1.4 or later, Python 3.7 only)
11-
- ``typing_extensions`` (3.7 or later, Python 3.7 only)
12-
- `numpy <http://www.numpy.org/>`__ (1.17 or later)
13-
- `pandas <http://pandas.pydata.org/>`__ (1.0 or later)
9+
- Python (3.8 or later)
10+
- `numpy <https://www.numpy.org/>`__ (1.18 or later)
11+
- `pandas <https://pandas.pydata.org/>`__ (1.1 or later)
1412

1513
.. _optional-dependencies:
1614

@@ -103,7 +101,7 @@ release is guaranteed to work.
103101

104102
You can see the actual minimum tested versions:
105103

106-
`<https://github.com/pydata/xarray/blob/main/ci/requirements/py37-min-all-deps.yml>`_
104+
`<https://github.com/pydata/xarray/blob/main/ci/requirements/py38-min-all-deps.yml>`_
107105

108106
.. _installation-instructions:
109107

doc/user-guide/weather-climate.rst

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ using the same formatting as the standard `datetime.strftime`_ convention .
127127
dates.strftime("%c")
128128
da["time"].dt.strftime("%Y%m%d")
129129
130+
Conversion between non-standard calendar and to/from pandas DatetimeIndexes is
131+
facilitated with the :py:meth:`xarray.Dataset.convert_calendar` method (also available as
132+
:py:meth:`xarray.DataArray.convert_calendar`). Here, like elsewhere in xarray, the ``use_cftime``
133+
argument controls which datetime backend is used in the output. The default (``None``) is to
134+
use `pandas` when possible, i.e. when the calendar is standard and dates are within 1678 and 2262.
135+
136+
.. ipython:: python
137+
138+
dates = xr.cftime_range(start="2001", periods=24, freq="MS", calendar="noleap")
139+
da_nl = xr.DataArray(np.arange(24), coords=[dates], dims=["time"], name="foo")
140+
da_std = da.convert_calendar("standard", use_cftime=True)
141+
142+
The data is unchanged, only the timestamps are modified. Further options are implemented
143+
for the special ``"360_day"`` calendar and for handling missing dates. There is also
144+
:py:meth:`xarray.Dataset.interp_calendar` (and :py:meth:`xarray.DataArray.interp_calendar`)
145+
for `interpolating` data between calendars.
146+
130147
For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
131148

132149
- `Partial datetime string indexing`_:
@@ -150,7 +167,8 @@ For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
150167

151168
- Access of basic datetime components via the ``dt`` accessor (in this case
152169
just "year", "month", "day", "hour", "minute", "second", "microsecond",
153-
"season", "dayofyear", "dayofweek", and "days_in_month"):
170+
"season", "dayofyear", "dayofweek", and "days_in_month") with the addition
171+
of "calendar", absent from pandas:
154172

155173
.. ipython:: python
156174
@@ -160,6 +178,7 @@ For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
160178
da.time.dt.dayofyear
161179
da.time.dt.dayofweek
162180
da.time.dt.days_in_month
181+
da.time.dt.calendar
163182
164183
- Rounding of datetimes to fixed frequencies via the ``dt`` accessor:
165184

@@ -214,30 +233,6 @@ For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
214233
215234
da.resample(time="81T", closed="right", label="right", base=3).mean()
216235
217-
.. note::
218-
219-
220-
For some use-cases it may still be useful to convert from
221-
a :py:class:`~xarray.CFTimeIndex` to a :py:class:`pandas.DatetimeIndex`,
222-
despite the difference in calendar types. The recommended way of doing this
223-
is to use the built-in :py:meth:`~xarray.CFTimeIndex.to_datetimeindex`
224-
method:
225-
226-
.. ipython:: python
227-
:okwarning:
228-
229-
modern_times = xr.cftime_range("2000", periods=24, freq="MS", calendar="noleap")
230-
da = xr.DataArray(range(24), [("time", modern_times)])
231-
da
232-
datetimeindex = da.indexes["time"].to_datetimeindex()
233-
da["time"] = datetimeindex
234-
235-
However in this case one should use caution to only perform operations which
236-
do not depend on differences between dates (e.g. differentiation,
237-
interpolation, or upsampling with resample), as these could introduce subtle
238-
and silent errors due to the difference in calendar types between the dates
239-
encoded in your data and the dates stored in memory.
240-
241236
.. _Timestamp-valid range: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timestamp-limitations
242237
.. _ISO 8601 standard: https://en.wikipedia.org/wiki/ISO_8601
243238
.. _partial datetime string indexing: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#partial-string-indexing

doc/whats-new.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,39 @@ New Features
2424
- New top-level function :py:func:`cross`. (:issue:`3279`, :pull:`5365`).
2525
By `Jimmy Westling <https://github.com/illviljan>`_.
2626

27+
- Enable the limit option for dask array in the following methods :py:meth:`DataArray.ffill`, :py:meth:`DataArray.bfill`, :py:meth:`Dataset.ffill` and :py:meth:`Dataset.bfill` (:issue:`6112`)
28+
By `Joseph Nowak <https://github.com/josephnowak>`_.
2729

2830
Breaking changes
2931
~~~~~~~~~~~~~~~~
32+
- Rely on matplotlib's default datetime converters instead of pandas' (:issue:`6102`, :pull:`6109`).
33+
By `Jimmy Westling <https://github.com/illviljan>`_.
34+
- Improve repr readability when there are a large number of dimensions in datasets or dataarrays by
35+
wrapping the text once the maximum display width has been exceeded. (:issue: `5546`, :pull:`5662`)
36+
By `Jimmy Westling <https://github.com/illviljan>`_.
3037

3138

3239
Deprecations
3340
~~~~~~~~~~~~
3441
- Removed the lock kwarg from the zarr and pydap backends, completing the deprecation cycle started in :issue:`5256`.
3542
By `Tom Nicholas <https://github.com/TomNicholas>`_.
43+
- Support for ``python 3.7`` has been dropped. (:pull:`5892`)
44+
By `Jimmy Westling <https://github.com/illviljan>`_.
3645

3746

3847
Bug fixes
3948
~~~~~~~~~
49+
- Properly support :py:meth:`DataArray.ffill`, :py:meth:`DataArray.bfill`, :py:meth:`Dataset.ffill` and :py:meth:`Dataset.bfill` along chunked dimensions (:issue:`6112`).
50+
By `Joseph Nowak <https://github.com/josephnowak>`_.
51+
52+
- Subclasses of ``byte`` and ``str`` (e.g. ``np.str_`` and ``np.bytes_``) will now serialise to disk rather than raising a ``ValueError: unsupported dtype for netCDF4 variable: object`` as they did previously (:pull:`5264`).
53+
By `Zeb Nicholls <https://github.com/znicholls>`_.
54+
55+
- Fix applying function with non-xarray arguments using :py:func:`xr.map_blocks`.
56+
By `Cindy Chiao <https://github.com/tcchiao>`_.
57+
58+
- `dt.season <https://xarray.pydata.org/en/stable/generated/xarray.DataArray.dt.season.html>`_ can now handle NaN and NaT. (:pull:`5876`).
59+
By `Pierre Loicq <https://github.com/pierreloicq>`_.
4060

4161

4262
Documentation
@@ -49,6 +69,9 @@ Internal Changes
4969
- Replace ``distutils.version`` with ``packaging.version`` (:issue:`6092`).
5070
By `Mathias Hauser <https://github.com/mathause>`_.
5171

72+
- Removed internal checks for ``pd.Panel`` (:issue:`6145`).
73+
By `Matthew Roeschke <https://github.com/mroeschke>`_.
74+
5275

5376
.. _whats-new.0.20.2:
5477

@@ -155,6 +178,8 @@ New Features
155178
- Added ``storage_options`` argument to :py:meth:`to_zarr` (:issue:`5601`, :pull:`5615`).
156179
By `Ray Bell <https://github.com/raybellwaves>`_, `Zachary Blackwood <https://github.com/blackary>`_ and
157180
`Nathan Lis <https://github.com/wxman22>`_.
181+
- Added calendar utilities :py:func:`DataArray.convert_calendar`, :py:func:`DataArray.interp_calendar`, :py:func:`date_range`, :py:func:`date_range_like` and :py:attr:`DataArray.dt.calendar` (:issue:`5155`, :pull:`5233`).
182+
By `Pascal Bourgault <https://github.com/aulemahal>`_.
158183
- Histogram plots are set with a title displaying the scalar coords if any, similarly to the other plots (:issue:`5791`, :pull:`5792`).
159184
By `Maxime Liquet <https://github.com/maximlt>`_.
160185
- Slice plots display the coords units in the same way as x/y/colorbar labels (:pull:`5847`).

requirements.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
# it exists to let GitHub build the repository dependency graph
33
# https://help.github.com/en/github/visualizing-repository-data-with-graphs/listing-the-packages-that-a-repository-depends-on
44

5-
numpy >= 1.17
6-
pandas >= 1.0
7-
setuptools >= 40.4
8-
typing-extensions >= 3.7
5+
numpy >= 1.18
6+
pandas >= 1.1

0 commit comments

Comments
 (0)