(self)
| 4517 | assert_equal(actual, expected) |
| 4518 | |
| 4519 | def test_sortby(self) -> None: |
| 4520 | da = DataArray( |
| 4521 | [[1, 2], [3, 4], [5, 6]], [("x", ["c", "b", "a"]), ("y", [1, 0])] |
| 4522 | ) |
| 4523 | |
| 4524 | sorted1d = DataArray( |
| 4525 | [[5, 6], [3, 4], [1, 2]], [("x", ["a", "b", "c"]), ("y", [1, 0])] |
| 4526 | ) |
| 4527 | |
| 4528 | sorted2d = DataArray( |
| 4529 | [[6, 5], [4, 3], [2, 1]], [("x", ["a", "b", "c"]), ("y", [0, 1])] |
| 4530 | ) |
| 4531 | |
| 4532 | expected = sorted1d |
| 4533 | dax = DataArray([100, 99, 98], [("x", ["c", "b", "a"])]) |
| 4534 | actual = da.sortby(dax) |
| 4535 | assert_equal(actual, expected) |
| 4536 | |
| 4537 | # test descending order sort |
| 4538 | actual = da.sortby(dax, ascending=False) |
| 4539 | assert_equal(actual, da) |
| 4540 | |
| 4541 | # test alignment (fills in nan for 'c') |
| 4542 | dax_short = DataArray([98, 97], [("x", ["b", "a"])]) |
| 4543 | actual = da.sortby(dax_short) |
| 4544 | assert_equal(actual, expected) |
| 4545 | |
| 4546 | # test multi-dim sort by 1D dataarray values |
| 4547 | expected = sorted2d |
| 4548 | dax = DataArray([100, 99, 98], [("x", ["c", "b", "a"])]) |
| 4549 | day = DataArray([90, 80], [("y", [1, 0])]) |
| 4550 | actual = da.sortby([day, dax]) |
| 4551 | assert_equal(actual, expected) |
| 4552 | |
| 4553 | expected = sorted1d |
| 4554 | actual = da.sortby("x") |
| 4555 | assert_equal(actual, expected) |
| 4556 | |
| 4557 | expected = sorted2d |
| 4558 | actual = da.sortby(["x", "y"]) |
| 4559 | assert_equal(actual, expected) |
| 4560 | |
| 4561 | @requires_bottleneck |
| 4562 | def test_rank(self) -> None: |
nothing calls this directly
no test coverage detected