html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue
https://github.com/pydata/xarray/issues/3883#issuecomment-630387515,https://api.github.com/repos/pydata/xarray/issues/3883,630387515,MDEyOklzc3VlQ29tbWVudDYzMDM4NzUxNQ==,10194086,2020-05-18T19:21:55Z,2020-10-27T14:27:50Z,MEMBER,"```python
%load_ext line_profiler
import numpy as np
import xarray as xr
from xarray.core.weighted import Weighted as w
shape_weights = (1000, 1000)
shape_data = (1000, 1000, 10)
add_nans = False
def lprun_weighted(shape_weights, shape_data, add_nans, skipna=None):
weights = xr.DataArray(np.random.randn(*shape_weights))
data = np.random.randn(*shape_data)
# add approximately 25 % NaNs
if add_nans:
c = int(data.size * 0.25)
data.ravel()[np.random.choice(data.size, c, replace=False)] = np.NaN
data = xr.DataArray(data)
return data.weighted(weights).mean(skipna=skipna)
%lprun -f w._reduce -f w._weighted_mean -f w._sum_of_weights -f w._weighted_sum -f w.__init__ -f lprun_weighted -u 1e-03 lprun_weighted(shape_weights, shape_data, add_nans, skipna=None)
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,587048587
https://github.com/pydata/xarray/issues/3883#issuecomment-633918109,https://api.github.com/repos/pydata/xarray/issues/3883,633918109,MDEyOklzc3VlQ29tbWVudDYzMzkxODEwOQ==,10194086,2020-05-26T09:33:40Z,2020-05-26T09:34:25Z,MEMBER,"`weighted(weights).mean(skipna=True)` calls
https://github.com/pydata/xarray/blob/d1f7cb8fd95d588d3f7a7e90916c25747b90ad5a/xarray/core/weighted.py#L143
and
https://github.com/pydata/xarray/blob/d1f7cb8fd95d588d3f7a7e90916c25747b90ad5a/xarray/core/weighted.py#L130
`da.fillna(0.0)` in turn calls `where(null(data), other)`. Thus `null`/ `notnull` is called twice. This could be optimized by doing `self.null = obj.null()` in `__init__(...)`. This might also allow `self.any_null = self.null.any()` to skip `NaN` handling if there are none. However, this needs more thinking if a `Dataset` is passed. Probably overkill but leaving this here for reference.
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,587048587
https://github.com/pydata/xarray/issues/3883#issuecomment-603717924,https://api.github.com/repos/pydata/xarray/issues/3883,603717924,MDEyOklzc3VlQ29tbWVudDYwMzcxNzkyNA==,10194086,2020-03-25T08:49:45Z,2020-03-25T08:49:45Z,MEMBER,maybe relevant: #1995,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,587048587