(
self,
x: np.ndarray,
minindex: int | float,
maxindex: int | float,
nanindex: int | None,
)
| 5580 | "ignore:Behaviour of argmin/argmax with neither dim nor :FutureWarning" |
| 5581 | ) |
| 5582 | def test_argmax_dim( |
| 5583 | self, |
| 5584 | x: np.ndarray, |
| 5585 | minindex: int | float, |
| 5586 | maxindex: int | float, |
| 5587 | nanindex: int | None, |
| 5588 | ) -> None: |
| 5589 | ar = xr.DataArray( |
| 5590 | x, dims=["x"], coords={"x": np.arange(x.size) * 4}, attrs=self.attrs |
| 5591 | ) |
| 5592 | indarr = xr.DataArray(np.arange(x.size, dtype=np.intp), dims=["x"]) |
| 5593 | |
| 5594 | if np.isnan(maxindex): |
| 5595 | with pytest.raises(ValueError): |
| 5596 | ar.argmax() |
| 5597 | return |
| 5598 | |
| 5599 | expected0 = {"x": indarr[maxindex]} |
| 5600 | for da in expected0.values(): |
| 5601 | da.attrs = self.attrs # Default keeps attrs for reduction operations |
| 5602 | result0 = ar.argmax(...) |
| 5603 | for key in expected0: |
| 5604 | assert_identical(result0[key], expected0[key]) |
| 5605 | |
| 5606 | result1 = ar.argmax(..., keep_attrs=True) |
| 5607 | expected1 = deepcopy(expected0) |
| 5608 | for da in expected1.values(): |
| 5609 | da.attrs = self.attrs |
| 5610 | for key in expected1: |
| 5611 | assert_identical(result1[key], expected1[key]) |
| 5612 | |
| 5613 | result2 = ar.argmax(..., skipna=False) |
| 5614 | if nanindex is not None and ar.dtype.kind != "O": |
| 5615 | expected2 = {"x": indarr.isel(x=nanindex, drop=True)} |
| 5616 | expected2[ |
| 5617 | "x" |
| 5618 | ].attrs = self.attrs # Default keeps attrs for reduction operations |
| 5619 | else: |
| 5620 | expected2 = expected0 |
| 5621 | |
| 5622 | for key in expected2: |
| 5623 | assert_identical(result2[key], expected2[key]) |
| 5624 | |
| 5625 | |
| 5626 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected