Uh oh!
There was an error while loading. Please reload this page.
Dask friendly check in .weighted() - #4559
Conversation
Uh oh!
There was an error while loading. Please reload this page.
jbusecke
commented
Nov 1, 2020
The Ci environments without dask are failing. Should I add some pytest skip logic, or what is the best way to handle this? |
max-sixty
commented
Nov 1, 2020
Yes, |
keewis
commented
Nov 1, 2020
since the test you added requires That won't fix all the failing tests, though: |
mathause
left a comment
There was a problem hiding this comment.
For simplicity I would use if dask_duck_array(weights):.
| weights = DataArray(weights).chunk({"dim_0": -1}) | ||
| weighted = data.weighted(weights) |
There was a problem hiding this comment.
You test that dask does not comoute:
xarray/xarray/tests/test_dask.py
Lines 189 to 190 in 83884a1
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
mathause
commented
Nov 1, 2020
I think you need to do someting along the lines of: ifdask_duck_array(weights):
importdask.arrayasdsadsa.map_blocks(_weight_check, weights.data, dtype=weights.dtype)
else:
_weight_check() |
jbusecke
commented
Nov 1, 2020
I did have to fiddle with this a bit. I did change |
| "`weights` cannot contain missing values. " | ||
| "Missing values can be replaced by `weights.fillna(0)`." | ||
| def _weight_check(w): | ||
| if np.isnan(w).any(): |
There was a problem hiding this comment.
.isnull() does a bit more than that: np.isnan won't detect NaT. @mathause, how likely is it to get datetime-like arrays here? They don't make much sense as weights, but as far as I can tell we don't check (I might be missing something, though)
There was a problem hiding this comment.
There is no check for that. A TimeDelta may make some sense as weights. DateTime not so much. I think we can get away with using np.isnan. A Date* array as weights containing NaT should be super uncommon.
There was a problem hiding this comment.
We could still operate on the dataarray instead of the dask/numpy array, but as @dcherian suggesred, that would be less efficient. I would be curious as to what penalties would actually occur when we use the weights.map_blocks compared to dask.array.map_blocks?
There was a problem hiding this comment.
- Could use
duck_array_ops.isnullto account fortimedelta64? It is weird to have it as a weight though. Does that work? - Re map_blocks: the xarray version adds tasks that create xarray objects wrapping every block in a dask array. That adds overhead which is totally unneccesary here.
jbusecke
commented
Nov 3, 2020
Do you think this works or are further changes needed? Many thanks for the guidance so far! |
max-sixty
left a comment
There was a problem hiding this comment.
Looks great to me. Want to add a whatsnew?
Uh oh!
There was an error while loading. Please reload this page.
| if is_duck_dask_array(weights.data): | ||
| import dask.array as dsa | ||
| weights.data = dsa.map_blocks( |
There was a problem hiding this comment.
| weights.data=dsa.map_blocks( | |
| weights=weights.copy(data=dsa.map_blocks( |
so we don't modify the original object. Could even do weights.data.map_blocks(...) to save some typing...
Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
.weighted().weighted()jbusecke
commented
Nov 4, 2020
I am getting some failures for |
jbusecke
commented
Nov 4, 2020
Similarly on |
jbusecke
commented
Nov 5, 2020
Ok I think this should be good to go. I have implemented all the requested changes. The remaining failures are related to other problems upstream (I think). Anything else I should add here? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Mathias Hauser <mathause@users.noreply.github.com>
jbusecke
commented
Nov 6, 2020
I am not understanding why that |
this CI is sometimes flaky, but it's usually enough to just rerun it. I'll do that for you once the other CI finished. |
jbusecke
commented
Nov 6, 2020
Seems like all the other test are passing (minus the two upstream problems discussed before). |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
mathause
commented
Nov 9, 2020
Thanks @jbusecke |
* initial changes * Using map_blocks to lazily mask input arrays, following #4559 * Adding lazy corr cov test with `raise_if_dask_computes` * adding test for one da without nans * checking ordering of arrays doesnt matter Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com> * adjust inputs to test * add test for array with no missing values * added whatsnew * fixing format issues Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
weighted()#4541isort . && black . && mypy . && flake8whats-new.rst