-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Rolling window with as_strided
#1837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 77 commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
789134c
Rolling_window for np.ndarray
fujiisoup fa4e857
Add pad method to Variable
fujiisoup 52915f3
Added rolling_window to DataArray and Dataset
fujiisoup b622007
remove pad_value option. Support dask.rolling_window
fujiisoup 36a1fe9
Refactor rolling.reduce
fujiisoup 71fed0f
add as_strided to npcompat. Tests added for reduce(np.nanmean)
fujiisoup 3960134
Support boolean in maybe_promote
fujiisoup 4bd38f3
move rolling_window into duck_array_op. Make DataArray.rolling_window…
fujiisoup af8362e
Added to_dataarray and to_dataset to rolling object.
fujiisoup 76db6b5
Use pad in rolling to make compatible to pandas. Expose pad_with_fill…
fujiisoup 87f53af
Refactor rolling
fujiisoup c23cedb
flake8
fujiisoup 9547c57
Added a comment for dask's pad.
fujiisoup 1f71cff
Use fastpath in rolling.to_dataarray
fujiisoup 724776f
Merge branch 'master' into rolling_window
fujiisoup 73862eb
Doc added.
fujiisoup 859bb5c
Revert not to use fastpath
fujiisoup d5fc24e
Merge branch 'master' into rolling_window
fujiisoup 05c72f0
Remove maybe_prompt for Boolean. Some improvements based on @shoyer's…
fujiisoup d55e498
Update test.
fujiisoup 9393eb2
Bug fix in test_rolling_count_correct
fujiisoup 9c71a50
fill_value for boolean array
fujiisoup 54975b4
rolling_window(array, axis, window) -> rolling_window(array, window, …
fujiisoup e907fdf
support stride in rolling.to_dataarray
fujiisoup 6482536
flake8
fujiisoup b8def4f
Improve doc. Add DataArrayRolling to api.rst
fujiisoup ff31589
Improve docs in common.rolling.
fujiisoup 6c011cb
Expose groupby docs to public
fujiisoup 684145a
Default fill_value=dtypes.NA, stride=1. Add comment for DataArrayRollig.
fujiisoup 3a7526e
Default fill_value=dtypes.NA, stride=1. Add comment for DataArrayRollig.
fujiisoup a0968d6
Add fill_value option to rolling.to_dataarray
fujiisoup ac4f00e
Convert non-numeric array in reduce.
fujiisoup fbfc262
Fill_value = False for boolean array in rolling.reduce
fujiisoup c757986
Support old numpy plus bottleneck combination. Suppress warning for a…
fujiisoup 8fd5fa3
flake8
fujiisoup ade5ba2
Add benchmark
fujiisoup 2d6897f
Dataset.count. Benchmark
fujiisoup 6461f84
Classize benchmark
fujiisoup aece1c4
Decoratorize for asv benchmark
fujiisoup d5ad4a0
Merge branch 'master' into rolling_window
fujiisoup 4189d71
Classize benchmarks/indexing.py
fujiisoup 081c928
Working with nanreduce
fujiisoup 75c1d7d
Support .sum for object dtype.
fujiisoup 452b219
Remove unused if-statements.
fujiisoup c5490c4
Default skipna for rolling.reduce
fujiisoup ab91394
Pass tests. Test added to make sure the consistency to pandas' behavior.
fujiisoup 9fa0812
Delete duplicate file. flake8
fujiisoup 0c1d49a
flake8 again
fujiisoup 9463937
Working with numpy<1.13
fujiisoup dce4e37
Revert "Classize benchmarks/indexing.py"
fujiisoup b3050cb
rolling_window with dask.ghost
fujiisoup 22f6d4a
Merge branch 'rolling_window_dask' into rolling_window
fujiisoup 19e0fca
Merge branch 'master' into rolling_window
fujiisoup d3b1e2b
Optimize rolling.count.
fujiisoup 2d06ec9
Merge branch 'master' into rolling_window
fujiisoup 734da93
Fixing style errors.
stickler-ci 1a000b8
Remove unused npcompat.nansum etc
fujiisoup 27ff67c
flake8
fujiisoup a2c7141
require_dask -> has_dask
fujiisoup 35dee9d
npcompat -> np
fujiisoup 137709f
flake8
fujiisoup cc82cdc
Skip tests for old numpy.
fujiisoup b246411
Improve doc. Optmize missing._get_valid_fill_mask
fujiisoup b3a2105
to_dataarray -> construct
fujiisoup b80fbfd
remove assert_allclose_with_nan
fujiisoup 3c010ae
Fixing style errors.
stickler-ci ab82f75
typo
fujiisoup b9f10cd
`to_dataset` -> `construct`
fujiisoup cc9c3d6
Update doc
fujiisoup 52cc48d
Merge branch 'master' into rolling_window
fujiisoup 2954cdf
Change boundary and add comments for dask_rolling_window.
fujiisoup f19e531
Refactor dask_array_ops.rolling_window and np_utils.rolling_window
fujiisoup a074df3
flake8
fujiisoup f6f78a5
Simplify tests
fujiisoup 0ec8aba
flake8 again.
fujiisoup 0261cfe
cleanup roling_window for dask.
fujiisoup a91c27f
Merge branch 'master' into rolling_window
fujiisoup c83d588
remove duplicates
fujiisoup 3bb4668
remvove duplicate
fujiisoup d0d89ce
flake8
fujiisoup eaba563
delete unnecessary file.
fujiisoup aeabdf5
Merge branch 'master' into rolling_window
fujiisoup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
from .computation import apply_ufunc | ||
from .utils import is_scalar | ||
from .npcompat import flip | ||
from . import rolling | ||
|
||
|
||
class BaseInterpolator(object): | ||
|
@@ -329,4 +330,8 @@ def _get_valid_fill_mask(arr, dim, limit): | |
'''helper function to determine values that can be filled when limit is not | ||
None''' | ||
kw = {dim: limit + 1} | ||
return arr.isnull().rolling(min_periods=1, **kw).sum() <= limit | ||
# we explicitly use construct method to avoid copy. | ||
new_dim = rolling._get_new_dimname(arr.dims, '_window') | ||
return (arr.isnull().rolling(min_periods=1, **kw) | ||
.construct(new_dim, fill_value=False) | ||
.sum(new_dim, skipna=False)) <= limit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my environment, this is faster than the original one with bottlneck (especially for small arrays) |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice!