Skip to content

Commit 0f39a30

Browse files
authored
Merge branch 'master' into fix_sel_float
2 parents 95bdcc7 + 01a9baa commit 0f39a30

26 files changed

+596
-306
lines changed

ci/requirements/py36-hypothesis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies:
2222
- seaborn
2323
- toolz
2424
- rasterio
25+
- boto3
2526
- bottleneck
2627
- zarr
2728
- pydap

ci/requirements/py36.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ dependencies:
2222
- seaborn
2323
- toolz
2424
- rasterio
25+
- boto3
2526
- bottleneck
2627
- zarr
2728
- pseudonetcdf>=3.0.1
2829
- cfgrib>=0.9.2
2930
- cdms2
30-
- pynio
31+
# Disabled due to conflicting dependencies:
32+
# https://github.com/pydata/xarray/issues/3154
33+
# - pynio
3134
- iris>=1.10
3235
- pydap
3336
- lxml

ci/requirements/py37-windows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ dependencies:
2222
- seaborn
2323
- toolz
2424
- rasterio
25+
- boto3
2526
- zarr

ci/requirements/py37.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies:
2323
- seaborn
2424
- toolz
2525
- rasterio
26+
- boto3
2627
- bottleneck
2728
- zarr
2829
- pseudonetcdf>=3.0.1

doc/conf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
'sphinx.ext.intersphinx',
6767
'sphinx.ext.extlinks',
6868
'sphinx.ext.mathjax',
69+
'sphinx.ext.napoleon',
6970
'numpydoc',
7071
'IPython.sphinxext.ipython_directive',
7172
'IPython.sphinxext.ipython_console_highlighting',
@@ -83,6 +84,10 @@
8384
}
8485

8586
autosummary_generate = True
87+
autodoc_typehints = 'none'
88+
89+
napoleon_use_param = True
90+
napoleon_use_rtype = True
8691

8792
numpydoc_class_members_toctree = True
8893
numpydoc_show_class_members = False

doc/io.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,9 @@ store is already present at that path, an error will be raised, preventing it
609609
from being overwritten. To override this behavior and overwrite an existing
610610
store, add ``mode='w'`` when invoking ``to_zarr``.
611611

612-
It is also possible to append to an existing store. For that, add ``mode='a'``
613-
and set ``append_dim`` to the name of the dimension along which to append.
612+
It is also possible to append to an existing store. For that, set
613+
``append_dim`` to the name of the dimension along which to append. ``mode``
614+
can be omitted as it will internally be set to ``'a'``.
614615

615616
.. ipython:: python
616617
:suppress:
@@ -628,7 +629,7 @@ and set ``append_dim`` to the name of the dimension along which to append.
628629
coords={'x': [10, 20, 30, 40],
629630
'y': [1,2,3,4,5],
630631
't': pd.date_range('2001-01-03', periods=2)})
631-
ds2.to_zarr('path/to/directory.zarr', mode='a', append_dim='t')
632+
ds2.to_zarr('path/to/directory.zarr', append_dim='t')
632633
633634
To store variable length strings use ``dtype=object``.
634635

doc/whats-new.rst

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,28 @@ New functions/methods
2828
By `Deepak Cherian <https://github.com/dcherian>`_ and `David Mertz
2929
<http://github.com/DavidMertz>`_.
3030

31+
- The xarray package is now discoverably by mypy (although typing hints
32+
coverage is not complete yet). mypy users can now remove from their setup.cfg
33+
the lines::
34+
35+
[mypy-xarray]
36+
ignore_missing_imports = True
37+
38+
By `Guido Imperiale <https://github.com/crusaderky>`_
39+
3140
Enhancements
3241
~~~~~~~~~~~~
3342

43+
- In :py:meth:`~xarray.Dataset.to_zarr`, passing ``mode`` is not mandatory if
44+
``append_dim`` is set, as it will automatically be set to ``'a'`` internally.
45+
By `David Brochart <https://github.com/davidbrochart>`_.
46+
3447
Bug fixes
3548
~~~~~~~~~
36-
37-
- Improved error handling and documentation for `.expand_dims()`
49+
- Fix regression introduced in v0.12.2 where ``copy(deep=True)`` would convert
50+
unicode indices to dtype=object (:issue:`3094`).
51+
By `Guido Imperiale <https://github.com/crusaderky>`_.
52+
- Improved error handling and documentation for `.expand_dims()`
3853
read-only view.
3954
- Fix tests for big-endian systems (:issue:`3125`).
4055
By `Graham Inggs <https://github.com/ginggs>`_.
@@ -44,6 +59,13 @@ Bug fixes
4459
- Fix KeyError that arises when using .sel method with float values
4560
different from coords float type (:issue:`3137`).
4661
By `Hasan Ahmad <https://github.com/HasanAhmadQ7>`_.
62+
- Fixed bug in ``combine_by_coords()`` causing a `ValueError` if the input had
63+
an unused dimension with coordinates which were not monotonic (:issue:`3150`).
64+
By `Tom Nicholas <http://github.com/TomNicholas>`_.
65+
- Fixed crash when applying ``distributed.Client.compute()`` to a DataArray
66+
(:issue:`3171`). By `Guido Imperiale <https://github.com/crusaderky>`_.
67+
68+
4769
.. _whats-new.0.12.3:
4870

4971
v0.12.3 (10 July 2019)
@@ -65,7 +87,6 @@ New functions/methods
6587
(:issue:`3026`).
6688
By `Julia Kent <https://github.com/jukent>`_.
6789

68-
6990
Enhancements
7091
~~~~~~~~~~~~
7192

@@ -85,6 +106,8 @@ Bug fixes
85106
- Fix HDF5 error that could arise when reading multiple groups from a file at
86107
once (:issue:`2954`).
87108
By `Stephan Hoyer <https://github.com/shoyer>`_.
109+
- Better error message when using groupby on an empty DataArray (:issue:`3037`).
110+
By `Hasan Ahmad <https://github.com/HasanAhmadQ7>`_.
88111

89112
.. _whats-new.0.12.2:
90113

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@
104104
tests_require=TESTS_REQUIRE,
105105
url=URL,
106106
packages=find_packages(),
107-
package_data={'xarray': ['tests/data/*']})
107+
package_data={'xarray': ['py.typed', 'tests/data/*']})

xarray/backends/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ def _validate_append_dim_and_encoding(ds_to_append, store, append_dim,
11021102
)
11031103

11041104

1105-
def to_zarr(dataset, store=None, mode='w-', synchronizer=None, group=None,
1105+
def to_zarr(dataset, store=None, mode=None, synchronizer=None, group=None,
11061106
encoding=None, compute=True, consolidated=False, append_dim=None):
11071107
"""This function creates an appropriate datastore for writing a dataset to
11081108
a zarr ztore
@@ -1118,7 +1118,7 @@ def to_zarr(dataset, store=None, mode='w-', synchronizer=None, group=None,
11181118
_validate_dataset_names(dataset)
11191119
_validate_attrs(dataset)
11201120

1121-
if mode == "a":
1121+
if mode == 'a':
11221122
_validate_datatypes_for_zarr_append(dataset)
11231123
_validate_append_dim_and_encoding(dataset, store, append_dim,
11241124
group=group,

xarray/core/alignment.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
import warnings
44
from collections import OrderedDict, defaultdict
55
from contextlib import suppress
6-
from typing import Any, Mapping, Optional, Tuple
6+
from typing import (
7+
Any,
8+
Dict,
9+
Hashable,
10+
Mapping,
11+
Optional,
12+
Tuple,
13+
Union,
14+
TYPE_CHECKING,
15+
)
716

817
import numpy as np
918
import pandas as pd
@@ -13,6 +22,10 @@
1322
from .utils import is_dict_like, is_full_slice
1423
from .variable import IndexVariable, Variable
1524

25+
if TYPE_CHECKING:
26+
from .dataarray import DataArray
27+
from .dataset import Dataset
28+
1629

1730
def _get_joiner(join):
1831
if join == 'outer':
@@ -169,8 +182,8 @@ def deep_align(objects, join='inner', copy=True, indexes=None,
169182
170183
This function is not public API.
171184
"""
172-
from .dataarray import DataArray
173-
from .dataset import Dataset
185+
from .dataarray import DataArray # noqa: F811
186+
from .dataset import Dataset # noqa: F811
174187

175188
if indexes is None:
176189
indexes = {}
@@ -222,7 +235,10 @@ def is_alignable(obj):
222235
return out
223236

224237

225-
def reindex_like_indexers(target, other):
238+
def reindex_like_indexers(
239+
target: Union['DataArray', 'Dataset'],
240+
other: Union['DataArray', 'Dataset'],
241+
) -> Dict[Hashable, pd.Index]:
226242
"""Extract indexers to align target with other.
227243
228244
Not public API.
@@ -236,7 +252,8 @@ def reindex_like_indexers(target, other):
236252
237253
Returns
238254
-------
239-
Dict[Any, pandas.Index] providing indexes for reindex keyword arguments.
255+
Dict[Hashable, pandas.Index] providing indexes for reindex keyword
256+
arguments.
240257
241258
Raises
242259
------
@@ -310,7 +327,7 @@ def reindex_variables(
310327
new_indexes : OrderedDict
311328
Dict of indexes associated with the reindexed variables.
312329
"""
313-
from .dataarray import DataArray
330+
from .dataarray import DataArray # noqa: F811
314331

315332
# create variables for the new dataset
316333
reindexed = OrderedDict() # type: OrderedDict[Any, Variable]
@@ -407,8 +424,8 @@ def _get_broadcast_dims_map_common_coords(args, exclude):
407424

408425
def _broadcast_helper(arg, exclude, dims_map, common_coords):
409426

410-
from .dataarray import DataArray
411-
from .dataset import Dataset
427+
from .dataarray import DataArray # noqa: F811
428+
from .dataset import Dataset # noqa: F811
412429

413430
def _set_dims(var):
414431
# Add excluded dims to a copy of dims_map

xarray/core/combine.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,13 @@ def combine_by_coords(datasets, compat='no_conflicts', data_vars='all',
501501
fill_value=fill_value)
502502

503503
# Check the overall coordinates are monotonically increasing
504-
for dim in concatenated.dims:
505-
if dim in concatenated:
506-
indexes = concatenated.indexes.get(dim)
507-
if not (indexes.is_monotonic_increasing
508-
or indexes.is_monotonic_decreasing):
509-
raise ValueError("Resulting object does not have monotonic"
510-
" global indexes along dimension {}"
511-
.format(dim))
504+
for dim in concat_dims:
505+
indexes = concatenated.indexes.get(dim)
506+
if not (indexes.is_monotonic_increasing
507+
or indexes.is_monotonic_decreasing):
508+
raise ValueError("Resulting object does not have monotonic"
509+
" global indexes along dimension {}"
510+
.format(dim))
512511
concatenated_grouped_by_data_vars.append(concatenated)
513512

514513
return merge(concatenated_grouped_by_data_vars, compat=compat,

xarray/core/common.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from textwrap import dedent
44
from typing import (
55
Any, Callable, Hashable, Iterable, Iterator, List, Mapping, MutableMapping,
6-
Optional, Tuple, TypeVar, Union)
6+
Tuple, TypeVar, Union)
77

88
import numpy as np
99
import pandas as pd
@@ -101,7 +101,7 @@ def __int__(self: Any) -> int:
101101
def __complex__(self: Any) -> complex:
102102
return complex(self.values)
103103

104-
def __array__(self: Any, dtype: Optional[DTypeLike] = None) -> np.ndarray:
104+
def __array__(self: Any, dtype: DTypeLike = None) -> np.ndarray:
105105
return np.asarray(self.values, dtype=dtype)
106106

107107
def __repr__(self) -> str:
@@ -448,7 +448,7 @@ def pipe(self, func: Union[Callable[..., T], Tuple[Callable[..., T], str]],
448448
return func(self, *args, **kwargs)
449449

450450
def groupby(self, group, squeeze: bool = True,
451-
restore_coord_dims: Optional[bool] = None):
451+
restore_coord_dims: bool = None):
452452
"""Returns a GroupBy object for performing grouped operations.
453453
454454
Parameters
@@ -501,7 +501,7 @@ def groupby(self, group, squeeze: bool = True,
501501
def groupby_bins(self, group, bins, right: bool = True, labels=None,
502502
precision: int = 3, include_lowest: bool = False,
503503
squeeze: bool = True,
504-
restore_coord_dims: Optional[bool] = None):
504+
restore_coord_dims: bool = None):
505505
"""Returns a GroupBy object for performing grouped operations.
506506
507507
Rather than using all unique values of `group`, the values are discretized
@@ -557,8 +557,8 @@ def groupby_bins(self, group, bins, right: bool = True, labels=None,
557557
'include_lowest':
558558
include_lowest})
559559

560-
def rolling(self, dim: Optional[Mapping[Hashable, int]] = None,
561-
min_periods: Optional[int] = None, center: bool = False,
560+
def rolling(self, dim: Mapping[Hashable, int] = None,
561+
min_periods: int = None, center: bool = False,
562562
**window_kwargs: int):
563563
"""
564564
Rolling window object.
@@ -621,7 +621,7 @@ def rolling(self, dim: Optional[Mapping[Hashable, int]] = None,
621621

622622
def rolling_exp(
623623
self,
624-
window: Optional[Mapping[Hashable, int]] = None,
624+
window: Mapping[Hashable, int] = None,
625625
window_type: str = 'span',
626626
**window_kwargs
627627
):
@@ -658,7 +658,7 @@ def rolling_exp(
658658

659659
return self._rolling_exp_cls(self, window, window_type)
660660

661-
def coarsen(self, dim: Optional[Mapping[Hashable, int]] = None,
661+
def coarsen(self, dim: Mapping[Hashable, int] = None,
662662
boundary: str = 'exact',
663663
side: Union[str, Mapping[Hashable, str]] = 'left',
664664
coord_func: str = 'mean',
@@ -721,11 +721,11 @@ def coarsen(self, dim: Optional[Mapping[Hashable, int]] = None,
721721
self, dim, boundary=boundary, side=side,
722722
coord_func=coord_func)
723723

724-
def resample(self, indexer: Optional[Mapping[Hashable, str]] = None,
725-
skipna=None, closed: Optional[str] = None,
726-
label: Optional[str] = None,
727-
base: int = 0, keep_attrs: Optional[bool] = None,
728-
loffset=None, restore_coord_dims: Optional[bool] = None,
724+
def resample(self, indexer: Mapping[Hashable, str] = None,
725+
skipna=None, closed: str = None,
726+
label: str = None,
727+
base: int = 0, keep_attrs: bool = None,
728+
loffset=None, restore_coord_dims: bool = None,
729729
**indexer_kwargs: str):
730730
"""Returns a Resample object for performing resampling operations.
731731
@@ -1003,7 +1003,7 @@ def __getitem__(self, value):
10031003
raise NotImplementedError
10041004

10051005

1006-
def full_like(other, fill_value, dtype: Optional[DTypeLike] = None):
1006+
def full_like(other, fill_value, dtype: DTypeLike = None):
10071007
"""Return a new object with the same shape and type as a given object.
10081008
10091009
Parameters
@@ -1044,7 +1044,7 @@ def full_like(other, fill_value, dtype: Optional[DTypeLike] = None):
10441044

10451045

10461046
def _full_like_variable(other, fill_value,
1047-
dtype: Optional[DTypeLike] = None):
1047+
dtype: DTypeLike = None):
10481048
"""Inner function of full_like, where other must be a variable
10491049
"""
10501050
from .variable import Variable
@@ -1061,13 +1061,13 @@ def _full_like_variable(other, fill_value,
10611061
return Variable(dims=other.dims, data=data, attrs=other.attrs)
10621062

10631063

1064-
def zeros_like(other, dtype: Optional[DTypeLike] = None):
1064+
def zeros_like(other, dtype: DTypeLike = None):
10651065
"""Shorthand for full_like(other, 0, dtype)
10661066
"""
10671067
return full_like(other, 0, dtype)
10681068

10691069

1070-
def ones_like(other, dtype: Optional[DTypeLike] = None):
1070+
def ones_like(other, dtype: DTypeLike = None):
10711071
"""Shorthand for full_like(other, 1, dtype)
10721072
"""
10731073
return full_like(other, 1, dtype)

0 commit comments

Comments
 (0)