home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 736131299

This data as json

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/4625#issuecomment-736131299 https://api.github.com/repos/pydata/xarray/issues/4625 736131299 MDEyOklzc3VlQ29tbWVudDczNjEzMTI5OQ== 2448579 2020-12-01T00:12:41Z 2020-12-01T00:12:41Z MEMBER

Ah this works (but we lose weights as a coord var).

``` python

simple customized weighted mean function

def mean_func(ds): return ds.weighted(ds.weights.reset_coords(drop=True)).mean('time') ```

Adding reset_coords fixes this because it gets rid of the non-dim coord weights.

https://github.com/pydata/xarray/blob/180e76d106c697b1dd94b814a49dc2d7e58c8551/xarray/core/weighted.py#L149 dot compares the weights coord var on ds and weights to decide if it should keep it.

The new call to .copy ends up making a copy of weights coord on the weights dataarray, so the lazy equality check fails. One solution is to avoid the call to copy and create the DataArray directly

python enc = weights.encoding weights = DataArray( weights.data.map_blocks(_weight_check, dtype=weights.dtype), dims=weights.dims, coords=weights.coords, attrs=weights.attrs ) weights.encoding = enc This works locally.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  753517739
Powered by Datasette · Queries took 238.034ms · About: xarray-datasette