MCPcopy Index your code
hub / github.com/pydata/xarray / test_eval_ndimensional

Function test_eval_ndimensional

xarray/tests/test_eval.py:60–94  ·  view source on GitHub ↗

Test that eval works with N-dimensional data where N > 2.

()

Source from the content-addressed store, hash-verified

58
59
60def test_eval_ndimensional() -> None:
61 """Test that eval works with N-dimensional data where N > 2."""
62 # Create a 3D dataset - this previously failed with pd.eval
63 rng = np.random.default_rng(42)
64 ds = Dataset(
65 {
66 "x": (["time", "lat", "lon"], rng.random((3, 4, 5))),
67 "y": (["time", "lat", "lon"], rng.random((3, 4, 5))),
68 }
69 )
70
71 # Basic arithmetic
72 actual = ds.eval("x + y")
73 expect = ds["x"] + ds["y"]
74 assert_identical(expect, actual)
75
76 # Assignment
77 actual = ds.eval("z = x + y")
78 assert "z" in actual.data_vars
79 assert_equal(ds["x"] + ds["y"], actual["z"])
80
81 # Complex expression
82 actual = ds.eval("x * 2 + y ** 2")
83 expect = ds["x"] * 2 + ds["y"] ** 2
84 assert_identical(expect, actual)
85
86 # Comparison
87 actual = ds.eval("x > y")
88 expect = ds["x"] > ds["y"]
89 assert_identical(expect, actual)
90
91 # Use bitwise operators for element-wise boolean operations
92 actual = ds.eval("(x > 0.5) & (y < 0.5)")
93 expect = (ds["x"] > 0.5) & (ds["y"] < 0.5)
94 assert_identical(expect, actual)
95
96
97def test_eval_chained_comparisons() -> None:

Callers

nothing calls this directly

Calls 4

evalMethod · 0.95
DatasetClass · 0.90
assert_identicalFunction · 0.90
assert_equalFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…