(
self,
x: np.ndarray,
minindex: int | float,
maxindex: int | float,
nanindex: int | None,
)
| 5534 | "ignore:Behaviour of argmin/argmax with neither dim nor :FutureWarning" |
| 5535 | ) |
| 5536 | def test_argmin_dim( |
| 5537 | self, |
| 5538 | x: np.ndarray, |
| 5539 | minindex: int | float, |
| 5540 | maxindex: int | float, |
| 5541 | nanindex: int | None, |
| 5542 | ) -> None: |
| 5543 | ar = xr.DataArray( |
| 5544 | x, dims=["x"], coords={"x": np.arange(x.size) * 4}, attrs=self.attrs |
| 5545 | ) |
| 5546 | indarr = xr.DataArray(np.arange(x.size, dtype=np.intp), dims=["x"]) |
| 5547 | |
| 5548 | if np.isnan(minindex): |
| 5549 | with pytest.raises(ValueError): |
| 5550 | ar.argmin() |
| 5551 | return |
| 5552 | |
| 5553 | expected0 = {"x": indarr[minindex]} |
| 5554 | for da in expected0.values(): |
| 5555 | da.attrs = self.attrs # Default keeps attrs for reduction operations |
| 5556 | result0 = ar.argmin(...) |
| 5557 | for key in expected0: |
| 5558 | assert_identical(result0[key], expected0[key]) |
| 5559 | |
| 5560 | result1 = ar.argmin(..., keep_attrs=True) |
| 5561 | expected1 = deepcopy(expected0) |
| 5562 | for da in expected1.values(): |
| 5563 | da.attrs = self.attrs |
| 5564 | for key in expected1: |
| 5565 | assert_identical(result1[key], expected1[key]) |
| 5566 | |
| 5567 | result2 = ar.argmin(..., skipna=False) |
| 5568 | if nanindex is not None and ar.dtype.kind != "O": |
| 5569 | expected2 = {"x": indarr.isel(x=nanindex, drop=True)} |
| 5570 | expected2[ |
| 5571 | "x" |
| 5572 | ].attrs = self.attrs # Default keeps attrs for reduction operations |
| 5573 | else: |
| 5574 | expected2 = expected0 |
| 5575 | |
| 5576 | for key in expected2: |
| 5577 | assert_identical(result2[key], expected2[key]) |
| 5578 | |
| 5579 | @pytest.mark.filterwarnings( |
| 5580 | "ignore:Behaviour of argmin/argmax with neither dim nor :FutureWarning" |
nothing calls this directly
no test coverage detected