Skip to content
forked from pydata/xarray

Commit 312ea14

Browse files
committed
Merge remote-tracking branch 'upstream/master' into interp-na-maxgap
* upstream/master: Whatsnew for pydata#3419 (pydata#3422) Revert changes made in pydata#3358 (pydata#3411) Python3.6 idioms (pydata#3419) Temporarily mark pseudonetcdf-3.1 as incompatible (pydata#3420) Fix and add test for groupby_bins() isnan TypeError. (pydata#3405) Update where docstring to make return value type more clear (pydata#3408) tests for arrays with units (pydata#3238) Fixes to the resample docs (pydata#3400)
2 parents 980f475 + b0c336f commit 312ea14

Some content is hidden

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

67 files changed

+1925
-233
lines changed

ci/requirements/py36-min-all-deps.yml

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies:
3131
- numba=0.44
3232
- numpy=1.14
3333
- pandas=0.24
34+
# - pint # See py36-min-nep18.yml
3435
- pip
3536
- pseudonetcdf=3.0
3637
- pydap=3.2

ci/requirements/py36-min-nep18.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ name: xarray-tests
22
channels:
33
- conda-forge
44
dependencies:
5-
# Optional dependencies that require NEP18, such as sparse,
5+
# Optional dependencies that require NEP18, such as sparse and pint,
66
# require drastically newer packages than everything else
77
- python=3.6
88
- coveralls
99
- dask=2.4
1010
- distributed=2.4
1111
- numpy=1.17
1212
- pandas=0.24
13+
- pint=0.9 # Actually not enough as it doesn't implement __array_function__yet!
1314
- pytest
1415
- pytest-cov
1516
- pytest-env

ci/requirements/py36.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ dependencies:
2727
- numba
2828
- numpy
2929
- pandas
30+
- pint
3031
- pip
31-
- pseudonetcdf
32+
- pseudonetcdf<3.1 # FIXME https://github.com/pydata/xarray/issues/3409
3233
- pydap
3334
- pynio
3435
- pytest

ci/requirements/py37-windows.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ dependencies:
2727
- numba
2828
- numpy
2929
- pandas
30+
- pint
3031
- pip
31-
- pseudonetcdf
32+
- pseudonetcdf<3.1 # FIXME https://github.com/pydata/xarray/issues/3409
3233
- pydap
3334
# - pynio # Not available on Windows
3435
- pytest

ci/requirements/py37.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ dependencies:
2727
- numba
2828
- numpy
2929
- pandas
30+
- pint
3031
- pip
31-
- pseudonetcdf
32+
- pseudonetcdf<3.1 # FIXME https://github.com/pydata/xarray/issues/3409
3233
- pydap
3334
- pynio
3435
- pytest

doc/gallery/plot_cartopy_facetgrid.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
==================================
43
Multiple plots and map projections

doc/gallery/plot_colorbar_center.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
==================
43
Centered colormaps

doc/gallery/plot_control_colorbar.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
===========================
43
Control the plot's colorbar

doc/gallery/plot_lines_from_2d.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
==================================
43
Multiple lines from a 2d DataArray

doc/gallery/plot_rasterio.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
.. _recipes.rasterio:
43

doc/gallery/plot_rasterio_rgb.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
.. _recipes.rasterio_rgb:
43

doc/installing.rst

+10-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ For plotting
6666
Alternative data containers
6767
~~~~~~~~~~~~~~~~~~~~~~~~~~~
6868
- `sparse <https://sparse.pydata.org/>`_: for sparse arrays
69+
- `pint <https://pint.readthedocs.io/>`_: for units of measure
70+
71+
.. note::
72+
73+
At the moment of writing, xarray requires a `highly experimental version of pint
74+
<https://github.com/andrewgsavage/pint/pull/6>`_ (install with
75+
``pip install git+https://github.com/andrewgsavage/pint.git@refs/pull/6/head)``.
76+
Even with it, interaction with non-numpy array libraries, e.g. dask or sparse, is broken.
77+
6978
- Any numpy-like objects that support
7079
`NEP-18 <https://numpy.org/neps/nep-0018-array-function-protocol.html>`_.
7180
Note that while such libraries theoretically should work, they are untested.
@@ -85,7 +94,7 @@ dependencies:
8594
(`NEP-29 <https://numpy.org/neps/nep-0029-deprecation_policy.html>`_)
8695
- **pandas:** 12 months
8796
- **scipy:** 12 months
88-
- **sparse** and other libraries that rely on
97+
- **sparse, pint** and other libraries that rely on
8998
`NEP-18 <https://numpy.org/neps/nep-0018-array-function-protocol.html>`_
9099
for integration: very latest available versions only, until the technology will have
91100
matured. This extends to dask when used in conjunction with any of these libraries.

doc/whats-new.rst

+31
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,37 @@ What's New
1818
v0.14.1 (unreleased)
1919
--------------------
2020

21+
New Features
22+
~~~~~~~~~~~~
23+
- Added integration tests against `pint <https://pint.readthedocs.io/>`_.
24+
(:pull:`3238`) by `Justus Magin <https://github.com/keewis>`_.
25+
26+
.. note::
27+
28+
At the moment of writing, these tests *as well as the ability to use pint in general*
29+
require `a highly experimental version of pint
30+
<https://github.com/andrewgsavage/pint/pull/6>`_ (install with
31+
``pip install git+https://github.com/andrewgsavage/pint.git@refs/pull/6/head)``.
32+
Even with it, interaction with non-numpy array libraries, e.g. dask or sparse, is broken.
33+
34+
Bug fixes
35+
~~~~~~~~~
36+
- Fix regression introduced in v0.14.0 that would cause a crash if dask is installed
37+
but cloudpickle isn't (:issue:`3401`) by `Rhys Doyle <https://github.com/rdoyle45>`_
38+
39+
Documentation
40+
~~~~~~~~~~~~~
41+
42+
- Fix the documentation of :py:meth:`DataArray.resample` and
43+
:py:meth:`Dataset.resample` and explicitly state that a
44+
datetime-like dimension is required. (:pull:`3400`)
45+
By `Justus Magin <https://github.com/keewis>`_.
46+
47+
Internal Changes
48+
~~~~~~~~~~~~~~~~
49+
50+
- Use Python 3.6 idioms throughout the codebase. (:pull:3419)
51+
By `Maximilian Roos <https://github.com/max-sixty>`_
2152

2253
.. _whats-new.0.14.0:
2354

setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ ignore_missing_imports = True
7373
ignore_missing_imports = True
7474
[mypy-pandas.*]
7575
ignore_missing_imports = True
76+
[mypy-pint.*]
77+
ignore_missing_imports = True
7678
[mypy-PseudoNetCDF.*]
7779
ignore_missing_imports = True
7880
[mypy-pydap.*]

xarray/_version.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
9494
return None, None
9595
else:
9696
if verbose:
97-
print("unable to find command, tried %s" % (commands,))
97+
print(f"unable to find command, tried {commands}")
9898
return None, None
9999
stdout = p.communicate()[0].strip()
100100
if sys.version_info[0] >= 3:
@@ -302,9 +302,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
302302
if verbose:
303303
fmt = "tag '%s' doesn't start with prefix '%s'"
304304
print(fmt % (full_tag, tag_prefix))
305-
pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (
306-
full_tag,
307-
tag_prefix,
305+
pieces["error"] = "tag '{}' doesn't start with prefix '{}'".format(
306+
full_tag, tag_prefix
308307
)
309308
return pieces
310309
pieces["closest-tag"] = full_tag[len(tag_prefix) :]

xarray/backends/api.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def open_mfdataset(
718718
autoclose=None,
719719
parallel=False,
720720
join="outer",
721-
**kwargs
721+
**kwargs,
722722
):
723723
"""Open multiple files as a single dataset.
724724
@@ -1258,9 +1258,7 @@ def _validate_append_dim_and_encoding(
12581258
return
12591259
if append_dim:
12601260
if append_dim not in ds.dims:
1261-
raise ValueError(
1262-
"{} not a valid dimension in the Dataset".format(append_dim)
1263-
)
1261+
raise ValueError(f"{append_dim} not a valid dimension in the Dataset")
12641262
for data_var in ds_to_append:
12651263
if data_var in ds:
12661264
if append_dim is None:

xarray/backends/file_manager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(
8383
kwargs=None,
8484
lock=None,
8585
cache=None,
86-
ref_counts=None
86+
ref_counts=None,
8787
):
8888
"""Initialize a FileManager.
8989
@@ -267,7 +267,7 @@ def __setstate__(self, state):
267267
def __repr__(self):
268268
args_string = ", ".join(map(repr, self._args))
269269
if self._mode is not _DEFAULT_MODE:
270-
args_string += ", mode={!r}".format(self._mode)
270+
args_string += f", mode={self._mode!r}"
271271
return "{}({!r}, {}, kwargs={})".format(
272272
type(self).__name__, self._opener, args_string, self._kwargs
273273
)

xarray/backends/locks.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import multiprocessing
22
import threading
33
import weakref
4-
from typing import Any, MutableMapping
4+
from typing import Any, MutableMapping, Optional
55

66
try:
77
from dask.utils import SerializableLock
@@ -62,7 +62,7 @@ def _get_lock_maker(scheduler=None):
6262
return _LOCK_MAKERS[scheduler]
6363

6464

65-
def _get_scheduler(get=None, collection=None):
65+
def _get_scheduler(get=None, collection=None) -> Optional[str]:
6666
"""Determine the dask scheduler that is being used.
6767
6868
None is returned if no dask scheduler is active.
@@ -86,10 +86,15 @@ def _get_scheduler(get=None, collection=None):
8686
except (ImportError, AttributeError):
8787
pass
8888

89-
if actual_get is dask.multiprocessing.get:
90-
return "multiprocessing"
91-
else:
92-
return "threaded"
89+
try:
90+
# As of dask=2.6, dask.multiprocessing requires cloudpickle to be installed
91+
# Dependency removed in https://github.com/dask/dask/pull/5511
92+
if actual_get is dask.multiprocessing.get:
93+
return "multiprocessing"
94+
except AttributeError:
95+
pass
96+
97+
return "threaded"
9398

9499

95100
def get_write_lock(key):

xarray/backends/netCDF4_.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _nc4_dtype(var):
137137
elif var.dtype.kind in ["i", "u", "f", "c", "S"]:
138138
dtype = var.dtype
139139
else:
140-
raise ValueError("unsupported dtype for netCDF4 variable: {}".format(var.dtype))
140+
raise ValueError(f"unsupported dtype for netCDF4 variable: {var.dtype}")
141141
return dtype
142142

143143

xarray/backends/netcdf3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def coerce_nc3_dtype(arr):
5050
cast_arr = arr.astype(new_dtype)
5151
if not (cast_arr == arr).all():
5252
raise ValueError(
53-
"could not safely cast array from dtype %s to %s" % (dtype, new_dtype)
53+
f"could not safely cast array from dtype {dtype} to {new_dtype}"
5454
)
5555
arr = cast_arr
5656
return arr

xarray/backends/pydap_.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _fix_attributes(attributes):
4949
# dot-separated key
5050
attributes.update(
5151
{
52-
"{}.{}".format(k, k_child): v_child
52+
f"{k}.{k_child}": v_child
5353
for k_child, v_child in attributes.pop(k).items()
5454
}
5555
)

xarray/coding/cftime_offsets.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ def __apply__(self, other):
638638

639639

640640
_FREQUENCY_CONDITION = "|".join(_FREQUENCIES.keys())
641-
_PATTERN = r"^((?P<multiple>\d+)|())(?P<freq>({}))$".format(_FREQUENCY_CONDITION)
641+
_PATTERN = fr"^((?P<multiple>\d+)|())(?P<freq>({_FREQUENCY_CONDITION}))$"
642642

643643

644644
# pandas defines these offsets as "Tick" objects, which for instance have
@@ -759,19 +759,15 @@ def _generate_range(start, end, periods, offset):
759759

760760
next_date = current + offset
761761
if next_date <= current:
762-
raise ValueError(
763-
"Offset {offset} did not increment date".format(offset=offset)
764-
)
762+
raise ValueError(f"Offset {offset} did not increment date")
765763
current = next_date
766764
else:
767765
while current >= end:
768766
yield current
769767

770768
next_date = current + offset
771769
if next_date >= current:
772-
raise ValueError(
773-
"Offset {offset} did not decrement date".format(offset=offset)
774-
)
770+
raise ValueError(f"Offset {offset} did not decrement date")
775771
current = next_date
776772

777773

xarray/coding/cftimeindex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def shift(self, n, freq):
403403
from .cftime_offsets import to_offset
404404

405405
if not isinstance(n, int):
406-
raise TypeError("'n' must be an int, got {}.".format(n))
406+
raise TypeError(f"'n' must be an int, got {n}.")
407407
if isinstance(freq, timedelta):
408408
return self + n * freq
409409
elif isinstance(freq, str):

xarray/coding/strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def shape(self):
228228
return self.array.shape[:-1]
229229

230230
def __repr__(self):
231-
return "%s(%r)" % (type(self).__name__, self.array)
231+
return "{}({!r})".format(type(self).__name__, self.array)
232232

233233
def __getitem__(self, key):
234234
# require slicing the last dimension completely

xarray/coding/times.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def infer_datetime_units(dates):
286286
# NumPy casting bug: https://github.com/numpy/numpy/issues/11096
287287
unique_timedeltas = to_timedelta_unboxed(unique_timedeltas)
288288
units = _infer_time_units_from_diff(unique_timedeltas)
289-
return "%s since %s" % (units, reference_date)
289+
return f"{units} since {reference_date}"
290290

291291

292292
def format_cftime_datetime(date):
@@ -341,7 +341,7 @@ def cftime_to_nptime(times):
341341
def _cleanup_netcdf_time_units(units):
342342
delta, ref_date = _unpack_netcdf_time_units(units)
343343
try:
344-
units = "%s since %s" % (delta, format_timestamp(ref_date))
344+
units = "{} since {}".format(delta, format_timestamp(ref_date))
345345
except OutOfBoundsDatetime:
346346
# don't worry about reifying the units if they're out of bounds
347347
pass

xarray/coding/variables.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,8 @@ def __array__(self, dtype=None):
7373
return self.func(self.array)
7474

7575
def __repr__(self):
76-
return "%s(%r, func=%r, dtype=%r)" % (
77-
type(self).__name__,
78-
self.array,
79-
self.func,
80-
self.dtype,
76+
return "{}({!r}, func={!r}, dtype={!r})".format(
77+
type(self).__name__, self.array, self.func, self.dtype
8178
)
8279

8380

@@ -113,7 +110,7 @@ def unpack_for_decoding(var):
113110

114111
def safe_setitem(dest, key, value, name=None):
115112
if key in dest:
116-
var_str = " on variable {!r}".format(name) if name else ""
113+
var_str = f" on variable {name!r}" if name else ""
117114
raise ValueError(
118115
"failed to prevent overwriting existing key {} in attrs{}. "
119116
"This is probably an encoding field used by xarray to describe "

0 commit comments

Comments
 (0)