Skip to content

Commit 1de9330

Browse files
committed
Add test for unsorted coords in stats routine
1 parent 7e51d9e commit 1de9330

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/test_reduce.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,28 @@ def test_var(dummy_lc_data, dummy_target_grid):
233233
dummy_lc_data["lc"].astype(float).regrid.stat(dummy_target_grid, "var"),
234234
make_expected_ds(expected_data)["lc"],
235235
)
236+
237+
238+
def test_unsorted_coords(dummy_lc_data, dummy_target_grid):
239+
"""Should pass if the input data has coords that are not ordered."""
240+
expected_data = np.array(
241+
[
242+
[0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
243+
[1.0, 0.75, 0.75, 0.0, 0.0, 0.0],
244+
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
245+
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
246+
[2.25, 0.0, 0.0, 0.0, 0.0, 0.25],
247+
[0.0, 1.6875, 2.25, 0.0, 0.25, 0.0],
248+
]
249+
)
250+
lc_data = dummy_lc_data.copy()
251+
252+
lc_data["scramble_order"] = (
253+
lc_data["latitude"]*0 + np.array([1, 3, 7, 0, 2, 8, 9, -1, 5, 11, 12])
254+
)
255+
lc_data = lc_data.sortby("scramble_order")
256+
257+
xr.testing.assert_equal(
258+
lc_data["lc"].astype(float).regrid.stat(dummy_target_grid, "var"),
259+
make_expected_ds(expected_data)["lc"],
260+
)

0 commit comments

Comments
 (0)