(self)
| 1125 | weighted_mean(dt.dataset) |
| 1126 | |
| 1127 | def test_map_keep_attrs(self) -> None: |
| 1128 | # test DatasetView.map(..., keep_attrs=...) |
| 1129 | data = xr.DataArray([1, 2, 3], dims="x", attrs={"da": "attrs"}) |
| 1130 | ds = xr.Dataset({"data": data}, attrs={"ds": "attrs"}) |
| 1131 | dt = DataTree(ds) |
| 1132 | |
| 1133 | def func_keep(ds): |
| 1134 | # x.mean() removes the attrs of the data_vars |
| 1135 | return ds.map(lambda x: x.mean(), keep_attrs=True) |
| 1136 | |
| 1137 | result = xr.map_over_datasets(func_keep, dt) |
| 1138 | expected = dt.mean(keep_attrs=True) |
| 1139 | xr.testing.assert_identical(result, expected) |
| 1140 | |
| 1141 | # DatasetView.map keeps attrs by default |
| 1142 | def func(ds): |
| 1143 | # ds.map and x.mean() both keep attrs by default |
| 1144 | return ds.map(lambda x: x.mean()) |
| 1145 | |
| 1146 | result = xr.map_over_datasets(func, dt) |
| 1147 | expected = dt.mean() |
| 1148 | xr.testing.assert_identical(result, expected) |
| 1149 | |
| 1150 | |
| 1151 | class TestAccess: |
nothing calls this directly
no test coverage detected