Skip to content

Commit f187ca1

Browse files
committed
Merge branch 'master' into fix/bounds_encode_2
* master: (31 commits) Add quantile method to GroupBy (pydata#2828) rolling_exp (nee ewm) (pydata#2650) Ensure explicitly indexed arrays are preserved (pydata#3027) add back dask-dev tests (pydata#3025) ENH: keepdims=True for xarray reductions (pydata#3033) Revert cmap fix (pydata#3038) Add "errors" keyword argument to drop() and drop_dims() (pydata#2994) (pydata#3028) More consistency checks (pydata#2859) Check types in travis (pydata#3024) Update issue templates (pydata#3019) Add pytest markers to avoid warnings (pydata#3023) Feature/merge errormsg (pydata#2971) More support for missing_value. (pydata#2973) Use flake8 rather than pycodestyle (pydata#3010) Pandas labels deprecation (pydata#3016) Pytest capture uses match, not message (pydata#3011) dask-dev tests to allowed failures in travis (pydata#3014) Fix 'to_masked_array' computing dask arrays twice (pydata#3006) str accessor (pydata#2991) fix safe_cast_to_index (pydata#3001) ...
2 parents 34d0e60 + b054c31 commit f187ca1

Some content is hidden

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

74 files changed

+3255
-386
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
#### MCVE Code Sample
11+
12+
In order for the maintainers to efficiently understand and prioritize issues, we ask you post a "Minimal, Complete and Verifiable Example" (MCVE): http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports
13+
14+
```python
15+
# Your code here
16+
17+
```
18+
19+
#### Problem Description
20+
21+
[this should explain **why** the current behavior is a problem and why the expected output is a better solution.]
22+
23+
#### Expected Output
24+
25+
#### Output of ``xr.show_versions()``
26+
27+
<details>
28+
# Paste the output here xr.show_versions() here
29+
30+
</details>

.pep8speaks.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
# File : .pep8speaks.yml
2-
3-
# This should be kept in sync with the duplicate config in the [pycodestyle]
4-
# block of setup.cfg.
1+
# https://github.com/OrkoHunter/pep8speaks for more info
2+
# pep8speaks will use the flake8 configs in `setup.cfg`
53

64
scanner:
7-
diff_only: False # If True, errors caused by only the patch are shown
8-
9-
pycodestyle:
10-
max-line-length: 79
11-
ignore: # Errors and warnings to ignore
12-
- E402 # module level import not at top of file
13-
- E731 # do not assign a lambda expression, use a def
14-
- E741 # ambiguous variable name
15-
- W503 # line break before binary operator
16-
- W504 # line break after binary operator
5+
diff_only: False
6+
linter: flake8

.travis.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ matrix:
2222
- env: CONDA_ENV=py36-zarr-dev
2323
- env: CONDA_ENV=docs
2424
- env: CONDA_ENV=lint
25+
- env: CONDA_ENV=typing
2526
- env: CONDA_ENV=py36-hypothesis
2627

2728
allow_failures:
@@ -30,6 +31,7 @@ matrix:
3031
- EXTRA_FLAGS="--run-flaky --run-network-tests"
3132
- env: CONDA_ENV=py36-pandas-dev
3233
- env: CONDA_ENV=py36-zarr-dev
34+
- env: CONDA_ENV=typing
3335

3436
before_install:
3537
- wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
@@ -40,9 +42,10 @@ before_install:
4042
- conda info -a
4143

4244
install:
43-
- if [[ "$CONDA_ENV" == "docs" ]]; then
45+
- |
46+
if [[ "$CONDA_ENV" == "docs" ]]; then
4447
conda env create -n test_env --file doc/environment.yml;
45-
elif [[ "$CONDA_ENV" == "lint" ]]; then
48+
elif [[ "$CONDA_ENV" == "lint" ]] || [[ "$CONDA_ENV" == "typing" ]] ; then
4649
conda env create -n test_env --file ci/requirements-py37.yml;
4750
else
4851
conda env create -n test_env --file ci/requirements-$CONDA_ENV.yml;
@@ -56,11 +59,14 @@ script:
5659
- which python
5760
- python --version
5861
- python -OO -c "import xarray"
59-
- if [[ "$CONDA_ENV" == "docs" ]]; then
62+
- |
63+
if [[ "$CONDA_ENV" == "docs" ]]; then
6064
cd doc;
6165
sphinx-build -n -j auto -b html -d _build/doctrees . _build/html;
6266
elif [[ "$CONDA_ENV" == "lint" ]]; then
63-
pycodestyle xarray ;
67+
flake8 ;
68+
elif [[ "$CONDA_ENV" == "typing" ]]; then
69+
mypy . ;
6470
elif [[ "$CONDA_ENV" == "py36-hypothesis" ]]; then
6571
pytest properties ;
6672
else

asv_bench/benchmarks/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from __future__ import absolute_import
2-
from __future__ import division
3-
from __future__ import print_function
1+
from __future__ import absolute_import, division, print_function
2+
43
import itertools
54

65
import numpy as np

ci/requirements-py36.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
- pytest-cov
1515
- pytest-env
1616
- coveralls
17-
- pycodestyle
17+
- flake8
1818
- numpy>=1.12
1919
- pandas>=0.19
2020
- scipy
@@ -24,12 +24,11 @@ dependencies:
2424
- bottleneck
2525
- zarr
2626
- pseudonetcdf>=3.0.1
27-
- eccodes
27+
- cfgrib>=0.9.2
2828
- cdms2
2929
- pynio
3030
- iris>=1.10
3131
- pydap
3232
- lxml
3333
- pip:
34-
- cfgrib>=0.9.2
3534
- mypy==0.660

ci/requirements-py37.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies:
1515
- pytest-cov
1616
- pytest-env
1717
- coveralls
18-
- pycodestyle
18+
- flake8
1919
- numpy>=1.12
2020
- pandas>=0.19
2121
- scipy
@@ -25,9 +25,9 @@ dependencies:
2525
- bottleneck
2626
- zarr
2727
- pseudonetcdf>=3.0.1
28+
- cfgrib>=0.9.2
2829
- lxml
29-
- eccodes
3030
- pydap
3131
- pip:
32-
- cfgrib>=0.9.2
3332
- mypy==0.650
33+
- numbagg

conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
"""Configuration for pytest."""
22

3+
import pytest
4+
35

46
def pytest_addoption(parser):
57
"""Add command-line flags for pytest."""
68
parser.addoption("--run-flaky", action="store_true",
79
help="runs flaky tests")
810
parser.addoption("--run-network-tests", action="store_true",
911
help="runs tests requiring a network connection")
12+
13+
14+
def pytest_collection_modifyitems(config, items):
15+
16+
if not config.getoption("--run-flaky"):
17+
skip_flaky = pytest.mark.skip(
18+
reason="set --run-flaky option to run flaky tests")
19+
for item in items:
20+
if "flaky" in item.keywords:
21+
item.add_marker(skip_flaky)
22+
23+
if not config.getoption("--run-network-tests"):
24+
skip_network = pytest.mark.skip(
25+
reason="set --run-network-tests option to run tests requiring an"
26+
"internet connection")
27+
for item in items:
28+
if "network" in item.keywords:
29+
item.add_marker(skip_network)

doc/api-hidden.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,4 @@
153153

154154
CFTimeIndex.shift
155155
CFTimeIndex.to_datetimeindex
156+
CFTimeIndex.strftime

doc/api.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ Computation
148148
Dataset.groupby
149149
Dataset.groupby_bins
150150
Dataset.rolling
151+
Dataset.rolling_exp
151152
Dataset.coarsen
152153
Dataset.resample
153154
Dataset.diff
@@ -189,6 +190,7 @@ Computation
189190
:py:attr:`~core.groupby.DatasetGroupBy.last`
190191
:py:attr:`~core.groupby.DatasetGroupBy.fillna`
191192
:py:attr:`~core.groupby.DatasetGroupBy.where`
193+
:py:attr:`~core.groupby.DatasetGroupBy.quantile`
192194

193195
Reshaping and reorganizing
194196
--------------------------
@@ -315,6 +317,7 @@ Computation
315317
DataArray.groupby
316318
DataArray.groupby_bins
317319
DataArray.rolling
320+
DataArray.rolling_exp
318321
DataArray.coarsen
319322
DataArray.dt
320323
DataArray.resample
@@ -324,6 +327,7 @@ Computation
324327
DataArray.quantile
325328
DataArray.differentiate
326329
DataArray.integrate
330+
DataArray.str
327331

328332
**Aggregation**:
329333
:py:attr:`~DataArray.all`
@@ -359,7 +363,7 @@ Computation
359363
:py:attr:`~core.groupby.DataArrayGroupBy.last`
360364
:py:attr:`~core.groupby.DataArrayGroupBy.fillna`
361365
:py:attr:`~core.groupby.DataArrayGroupBy.where`
362-
366+
:py:attr:`~core.groupby.DataArrayGroupBy.quantile`
363367

364368
Reshaping and reorganizing
365369
--------------------------
@@ -460,6 +464,7 @@ Dataset methods
460464
:toctree: generated/
461465

462466
open_dataset
467+
load_dataset
463468
open_mfdataset
464469
open_rasterio
465470
open_zarr
@@ -487,6 +492,7 @@ DataArray methods
487492
:toctree: generated/
488493

489494
open_dataarray
495+
load_dataarray
490496
DataArray.to_dataset
491497
DataArray.to_netcdf
492498
DataArray.to_pandas
@@ -532,6 +538,7 @@ Rolling objects
532538
core.rolling.DatasetRolling
533539
core.rolling.DatasetRolling.construct
534540
core.rolling.DatasetRolling.reduce
541+
core.rolling_exp.RollingExp
535542

536543
Resample objects
537544
================
@@ -555,6 +562,15 @@ Resample objects also implement the GroupBy interface
555562
core.resample.DatasetResample.nearest
556563
core.resample.DatasetResample.pad
557564

565+
Accessors
566+
=========
567+
568+
.. autosummary::
569+
:toctree: generated/
570+
571+
core.accessor_dt.DatetimeAccessor
572+
core.accessor_str.StringAccessor
573+
558574
Custom Indexes
559575
==============
560576
.. autosummary::

doc/computation.rst

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ Use :py:func:`~xarray.where` to conditionally switch between values:
4545
4646
xr.where(arr > 0, 'positive', 'negative')
4747
48+
Use `@` to perform matrix multiplication:
49+
50+
.. ipython:: python
51+
52+
arr @ arr
53+
4854
Data arrays also implement many :py:class:`numpy.ndarray` methods:
4955

5056
.. ipython:: python
@@ -143,20 +149,35 @@ name of the dimension as a key (e.g. ``y``) and the window size as the value
143149
144150
arr.rolling(y=3)
145151
146-
The label position and minimum number of periods in the rolling window are
147-
controlled by the ``center`` and ``min_periods`` arguments:
152+
Aggregation and summary methods can be applied directly to the ``Rolling``
153+
object:
148154

149155
.. ipython:: python
150156
151-
arr.rolling(y=3, min_periods=2, center=True)
157+
r = arr.rolling(y=3)
158+
r.reduce(np.std)
159+
r.mean()
152160
153-
Aggregation and summary methods can be applied directly to the ``Rolling`` object:
161+
Aggregation results are assigned the coordinate at the end of each window by
162+
default, but can be centered by passing ``center=True`` when constructing the
163+
``Rolling`` object:
154164

155165
.. ipython:: python
156166
157-
r = arr.rolling(y=3)
167+
r = arr.rolling(y=3, center=True)
168+
r.mean()
169+
170+
As can be seen above, aggregations of windows which overlap the border of the
171+
array produce ``nan``s. Setting ``min_periods`` in the call to ``rolling``
172+
changes the minimum number of observations within the window required to have
173+
a value when aggregating:
174+
175+
.. ipython:: python
176+
177+
r = arr.rolling(y=3, min_periods=2)
178+
r.mean()
179+
r = arr.rolling(y=3, center=True, min_periods=2)
158180
r.mean()
159-
r.reduce(np.std)
160181
161182
Note that rolling window aggregations are faster when bottleneck_ is installed.
162183

@@ -169,6 +190,22 @@ We can also manually iterate through ``Rolling`` objects:
169190
for label, arr_window in r:
170191
# arr_window is a view of x
171192
193+
.. _comput.rolling_exp:
194+
195+
While ``rolling`` provides a simple moving average, ``DataArray`` also supports
196+
an exponential moving average with :py:meth:`~xarray.DataArray.rolling_exp`.
197+
This is similiar to pandas' ``ewm`` method. numbagg_ is required.
198+
199+
.. _numbagg: https://github.com/shoyer/numbagg
200+
201+
.. code:: python
202+
203+
arr.rolling_exp(y=3).mean()
204+
205+
The ``rolling_exp`` method takes a ``window_type`` kwarg, which can be ``'alpha'``,
206+
``'com'`` (for ``center-of-mass``), ``'span'``, and ``'halflife'``. The default is
207+
``span``.
208+
172209
Finally, the rolling object has a ``construct`` method which returns a
173210
view of the original ``DataArray`` with the windowed dimension in
174211
the last position.

0 commit comments

Comments
 (0)