MCPcopy
hub / github.com/pydata/xarray / test_map_non_dataarray_outputs

Method test_map_non_dataarray_outputs

xarray/tests/test_dataset.py:6574–6597  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

6572 assert ds["x"].attrs != actual["x"].attrs
6573
6574 def test_map_non_dataarray_outputs(self) -> None:
6575 # Test that map handles non-DataArray outputs by converting them
6576 # Regression test for GH10835
6577 ds = xr.Dataset({"foo": ("x", [1, 2, 3]), "bar": ("y", [4, 5])})
6578
6579 # Scalar output
6580 result = ds.map(lambda x: 1)
6581 expected = xr.Dataset({"foo": 1, "bar": 1})
6582 assert_identical(result, expected)
6583
6584 # Numpy array output with same shape
6585 result = ds.map(lambda x: x.values)
6586 expected = ds.copy()
6587 assert_identical(result, expected)
6588
6589 # Mixed: some return scalars, some return arrays
6590 def mixed_func(x):
6591 if "x" in x.dims:
6592 return 42
6593 return x
6594
6595 result = ds.map(mixed_func)
6596 expected = xr.Dataset({"foo": 42, "bar": ("y", [4, 5])})
6597 assert_identical(result, expected)
6598
6599 def test_apply_pending_deprecated_map(self) -> None:
6600 data = create_test_data()

Callers

nothing calls this directly

Calls 3

mapMethod · 0.95
copyMethod · 0.95
assert_identicalFunction · 0.90

Tested by

no test coverage detected