-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rolling window with
as_strided
(#1837)
* Rolling_window for np.ndarray * Add pad method to Variable * Added rolling_window to DataArray and Dataset * remove pad_value option. Support dask.rolling_window * Refactor rolling.reduce * add as_strided to npcompat. Tests added for reduce(np.nanmean) * Support boolean in maybe_promote * move rolling_window into duck_array_op. Make DataArray.rolling_window public. * Added to_dataarray and to_dataset to rolling object. * Use pad in rolling to make compatible to pandas. Expose pad_with_fill_value to public. * Refactor rolling * flake8 * Added a comment for dask's pad. * Use fastpath in rolling.to_dataarray * Doc added. * Revert not to use fastpath * Remove maybe_prompt for Boolean. Some improvements based on @shoyer's review. * Update test. * Bug fix in test_rolling_count_correct * fill_value for boolean array * rolling_window(array, axis, window) -> rolling_window(array, window, axis) * support stride in rolling.to_dataarray * flake8 * Improve doc. Add DataArrayRolling to api.rst * Improve docs in common.rolling. * Expose groupby docs to public * Default fill_value=dtypes.NA, stride=1. Add comment for DataArrayRollig. * Default fill_value=dtypes.NA, stride=1. Add comment for DataArrayRollig. * Add fill_value option to rolling.to_dataarray * Convert non-numeric array in reduce. * Fill_value = False for boolean array in rolling.reduce * Support old numpy plus bottleneck combination. Suppress warning for all-nan slice reduce. * flake8 * Add benchmark * Dataset.count. Benchmark * Classize benchmark * Decoratorize for asv benchmark * Classize benchmarks/indexing.py * Working with nanreduce * Support .sum for object dtype. * Remove unused if-statements. * Default skipna for rolling.reduce * Pass tests. Test added to make sure the consistency to pandas' behavior. * Delete duplicate file. flake8 * flake8 again * Working with numpy<1.13 * Revert "Classize benchmarks/indexing.py" This reverts commit 4189d71. * rolling_window with dask.ghost * Optimize rolling.count. * Fixing style errors. * Remove unused npcompat.nansum etc * flake8 * require_dask -> has_dask * npcompat -> np * flake8 * Skip tests for old numpy. * Improve doc. Optmize missing._get_valid_fill_mask * to_dataarray -> construct * remove assert_allclose_with_nan * Fixing style errors. * typo * `to_dataset` -> `construct` * Update doc * Change boundary and add comments for dask_rolling_window. * Refactor dask_array_ops.rolling_window and np_utils.rolling_window * flake8 * Simplify tests * flake8 again. * cleanup roling_window for dask. * remove duplicates * remvove duplicate * flake8 * delete unnecessary file.
- Loading branch information
Showing
19 changed files
with
824 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import xarray as xr | ||
|
||
from . import parameterized, randn, requires_dask | ||
|
||
nx = 3000 | ||
ny = 2000 | ||
nt = 1000 | ||
window = 20 | ||
|
||
|
||
class Rolling(object): | ||
def setup(self, *args, **kwargs): | ||
self.ds = xr.Dataset( | ||
{'var1': (('x', 'y'), randn((nx, ny), frac_nan=0.1)), | ||
'var2': (('x', 't'), randn((nx, nt))), | ||
'var3': (('t', ), randn(nt))}, | ||
coords={'x': np.arange(nx), | ||
'y': np.linspace(0, 1, ny), | ||
't': pd.date_range('1970-01-01', periods=nt, freq='D'), | ||
'x_coords': ('x', np.linspace(1.1, 2.1, nx))}) | ||
|
||
@parameterized(['func', 'center'], | ||
(['mean', 'count'], [True, False])) | ||
def time_rolling(self, func, center): | ||
getattr(self.ds.rolling(x=window, center=center), func)() | ||
|
||
@parameterized(['window_', 'min_periods'], | ||
([20, 40], [5, None])) | ||
def time_rolling_np(self, window_, min_periods): | ||
self.ds.rolling(x=window_, center=False, | ||
min_periods=min_periods).reduce(getattr(np, 'nanmean')) | ||
|
||
@parameterized(['center', 'stride'], | ||
([True, False], [1, 200])) | ||
def time_rolling_construct(self, center, stride): | ||
self.ds.rolling(x=window, center=center).construct( | ||
'window_dim', stride=stride).mean(dim='window_dim') | ||
|
||
|
||
class RollingDask(Rolling): | ||
def setup(self, *args, **kwargs): | ||
requires_dask() | ||
super(RollingDask, self).setup(**kwargs) | ||
self.ds = self.ds.chunk({'x': 100, 'y': 50, 't': 50}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.