Skip to content

Commit 52466c8

Browse files
committed
Merge branch 'main' into Illviljan-dont_transpose_1d_arrays_during_interp
2 parents e56d87f + 64ed93e commit 52466c8

20 files changed

+775
-164
lines changed

.github/workflows/ci-pre-commit-autoupdate.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jobs:
3535
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3636
EXECUTE_COMMANDS: |
3737
python -m pre_commit autoupdate
38-
python .github/workflows/sync_linter_versions.py .pre-commit-config.yaml ci/requirements/mypy_only
3938
python -m pre_commit run --all-files
4039
COMMIT_MESSAGE: 'pre-commit: autoupdate hook versions'
4140
COMMIT_NAME: 'github-actions[bot]'

.github/workflows/sync_linter_versions.py

Lines changed: 0 additions & 76 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ repos:
88
- id: check-yaml
99
# isort should run before black as black sometimes tweaks the isort output
1010
- repo: https://github.com/PyCQA/isort
11-
rev: 5.9.1
11+
rev: 5.9.2
1212
hooks:
1313
- id: isort
1414
# https://github.com/python/black#version-control-integration
1515
- repo: https://github.com/psf/black
16-
rev: 21.6b0
16+
rev: 21.7b0
1717
hooks:
1818
- id: black
1919
- repo: https://github.com/keewis/blackdoc
20-
rev: v0.3.3
20+
rev: v0.3.4
2121
hooks:
2222
- id: blackdoc
2323
- repo: https://gitlab.com/pycqa/flake8
@@ -30,7 +30,6 @@ repos:
3030
# - id: velin
3131
# args: ["--write", "--compact"]
3232
- repo: https://github.com/pre-commit/mirrors-mypy
33-
# version must correspond to the one in .github/workflows/ci-additional.yaml
3433
rev: v0.910
3534
hooks:
3635
- id: mypy

ci/install-upstream-wheels.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ conda uninstall -y --force \
77
matplotlib \
88
dask \
99
distributed \
10+
fsspec \
1011
zarr \
1112
cftime \
1213
rasterio \
@@ -40,4 +41,5 @@ python -m pip install \
4041
git+https://github.com/mapbox/rasterio \
4142
git+https://github.com/hgrecco/pint \
4243
git+https://github.com/pydata/bottleneck \
43-
git+https://github.com/pydata/sparse
44+
git+https://github.com/pydata/sparse \
45+
git+https://github.com/intake/filesystem_spec

doc/getting-started-guide/installing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ dependencies:
9696
- **setuptools:** 42 months (but no older than 40.4)
9797
- **numpy:** 18 months
9898
(`NEP-29 <https://numpy.org/neps/nep-0029-deprecation_policy.html>`_)
99-
- **dask and dask.distributed:** 12 months (but no older than 2.9)
99+
- **dask and dask.distributed:** 12 months
100100
- **sparse, pint** and other libraries that rely on
101101
`NEP-18 <https://numpy.org/neps/nep-0018-array-function-protocol.html>`_
102102
for integration: very latest available versions only, until the technology will have

doc/whats-new.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ v0.18.3 (unreleased)
2121

2222
New Features
2323
~~~~~~~~~~~~
24+
- Allow passing argument ``missing_dims`` to :py:meth:`Variable.transpose` and :py:meth:`Dataset.transpose`
25+
(:issue:`5550`, :pull:`5586`)
26+
By `Giacomo Caria <https://github.com/gcaria>`_.
2427
- Allow passing a dictionary as coords to a :py:class:`DataArray` (:issue:`5527`,
2528
reverts :pull:`1539`, which had deprecated this due to python's inconsistent ordering in earlier versions).
2629
By `Sander van Rijn <https://github.com/sjvrijn>`_.
@@ -62,6 +65,10 @@ Breaking changes
6265
pre-existing array values. This is a safer default than the prior ``mode="a"``,
6366
and allows for higher performance writes (:pull:`5252`).
6467
By `Stephan Hoyer <https://github.com/shoyer>`_.
68+
- The main parameter to :py:func:`combine_by_coords` is renamed to `data_objects` instead
69+
of `datasets` so anyone calling this method using a named parameter will need to update
70+
the name accordingly (:issue:`3248`, :pull:`4696`).
71+
By `Augustus Ijams <https://github.com/aijams>`_.
6572

6673
Deprecations
6774
~~~~~~~~~~~~
@@ -85,6 +92,9 @@ Bug fixes
8592
- Plotting a pcolormesh with ``xscale="log"`` and/or ``yscale="log"`` works as
8693
expected after improving the way the interval breaks are generated (:issue:`5333`).
8794
By `Santiago Soler <https://github.com/santisoler>`_
95+
- :py:func:`combine_by_coords` can now handle combining a list of unnamed
96+
``DataArray`` as input (:issue:`3248`, :pull:`4696`).
97+
By `Augustus Ijams <https://github.com/aijams>`_.
8898

8999

90100
Documentation
@@ -146,20 +156,14 @@ New Features
146156

147157
Breaking changes
148158
~~~~~~~~~~~~~~~~
149-
- The main parameter to :py:func:`combine_by_coords` is renamed to `data_objects` instead
150-
of `datasets` so anyone calling this method using a named parameter will need to update
151-
the name accordingly (:issue:`3248`, :pull:`4696`).
152-
By `Augustus Ijams <https://github.com/aijams>`_.
159+
153160

154161
Deprecations
155162
~~~~~~~~~~~~
156163

157164

158165
Bug fixes
159166
~~~~~~~~~
160-
- :py:func:`combine_by_coords` can now handle combining a list of unnamed
161-
``DataArray`` as input (:issue:`3248`, :pull:`4696`).
162-
By `Augustus Ijams <https://github.com/aijams>`_.
163167
- Opening netCDF files from a path that doesn't end in ``.nc`` without supplying
164168
an explicit ``engine`` works again (:issue:`5295`), fixing a bug introduced in
165169
0.18.0.

xarray/backends/zarr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ def open_zarr(
737737
See Also
738738
--------
739739
open_dataset
740+
open_mfdataset
740741
741742
References
742743
----------

xarray/core/dataset.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4543,7 +4543,11 @@ def drop_dims(
45434543
drop_vars = {k for k, v in self._variables.items() if set(v.dims) & drop_dims}
45444544
return self.drop_vars(drop_vars)
45454545

4546-
def transpose(self, *dims: Hashable) -> "Dataset":
4546+
def transpose(
4547+
self,
4548+
*dims: Hashable,
4549+
missing_dims: str = "raise",
4550+
) -> "Dataset":
45474551
"""Return a new Dataset object with all array dimensions transposed.
45484552
45494553
Although the order of dimensions on each array will change, the dataset
@@ -4554,6 +4558,12 @@ def transpose(self, *dims: Hashable) -> "Dataset":
45544558
*dims : hashable, optional
45554559
By default, reverse the dimensions on each array. Otherwise,
45564560
reorder the dimensions to this order.
4561+
missing_dims : {"raise", "warn", "ignore"}, default: "raise"
4562+
What to do if dimensions that should be selected from are not present in the
4563+
Dataset:
4564+
- "raise": raise an exception
4565+
- "warn": raise a warning, and ignore the missing dimensions
4566+
- "ignore": ignore the missing dimensions
45574567
45584568
Returns
45594569
-------
@@ -4572,12 +4582,10 @@ def transpose(self, *dims: Hashable) -> "Dataset":
45724582
numpy.transpose
45734583
DataArray.transpose
45744584
"""
4575-
if dims:
4576-
if set(dims) ^ set(self.dims) and ... not in dims:
4577-
raise ValueError(
4578-
f"arguments to transpose ({dims}) must be "
4579-
f"permuted dataset dimensions ({tuple(self.dims)})"
4580-
)
4585+
# Use infix_dims to check once for missing dimensions
4586+
if len(dims) != 0:
4587+
_ = list(infix_dims(dims, self.dims, missing_dims))
4588+
45814589
ds = self.copy()
45824590
for name, var in self._variables.items():
45834591
var_dims = tuple(dim for dim in dims if dim in (var.dims + (...,)))

xarray/core/variable.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,14 +1378,24 @@ def roll(self, shifts=None, **shifts_kwargs):
13781378
result = result._roll_one_dim(dim, count)
13791379
return result
13801380

1381-
def transpose(self, *dims) -> "Variable":
1381+
def transpose(
1382+
self,
1383+
*dims,
1384+
missing_dims: str = "raise",
1385+
) -> "Variable":
13821386
"""Return a new Variable object with transposed dimensions.
13831387
13841388
Parameters
13851389
----------
13861390
*dims : str, optional
13871391
By default, reverse the dimensions. Otherwise, reorder the
13881392
dimensions to this order.
1393+
missing_dims : {"raise", "warn", "ignore"}, default: "raise"
1394+
What to do if dimensions that should be selected from are not present in the
1395+
Variable:
1396+
- "raise": raise an exception
1397+
- "warn": raise a warning, and ignore the missing dimensions
1398+
- "ignore": ignore the missing dimensions
13891399
13901400
Returns
13911401
-------
@@ -1404,7 +1414,9 @@ def transpose(self, *dims) -> "Variable":
14041414
"""
14051415
if len(dims) == 0:
14061416
dims = self.dims[::-1]
1407-
dims = tuple(infix_dims(dims, self.dims))
1417+
else:
1418+
dims = tuple(infix_dims(dims, self.dims, missing_dims))
1419+
14081420
if len(dims) < 2 or dims == self.dims:
14091421
# no need to transpose if only one dimension
14101422
# or dims are in same order

0 commit comments

Comments
 (0)