MCPcopy
hub / github.com/pydata/xarray / test_argmax

Method test_argmax

xarray/tests/test_dataarray.py:5256–5290  ·  view source on GitHub ↗
(
        self,
        x: np.ndarray,
        minindex: int | float,
        maxindex: int | float,
        nanindex: int | None,
    )

Source from the content-addressed store, hash-verified

5254 "ignore:Behaviour of argmin/argmax with neither dim nor :FutureWarning"
5255 )
5256 def test_argmax(
5257 self,
5258 x: np.ndarray,
5259 minindex: int | float,
5260 maxindex: int | float,
5261 nanindex: int | None,
5262 ) -> None:
5263 ar = xr.DataArray(
5264 x, dims=["x"], coords={"x": np.arange(x.size) * 4}, attrs=self.attrs
5265 )
5266 indarr = xr.DataArray(np.arange(x.size, dtype=np.intp), dims=["x"])
5267
5268 if np.isnan(maxindex):
5269 with pytest.raises(ValueError):
5270 ar.argmax()
5271 return
5272
5273 expected0 = indarr[maxindex]
5274 expected0.attrs = self.attrs # Default keeps attrs for reduction operations
5275 result0 = ar.argmax()
5276 assert_identical(result0, expected0)
5277
5278 result1 = ar.argmax(keep_attrs=True)
5279 expected1 = expected0.copy()
5280 expected1.attrs = self.attrs
5281 assert_identical(result1, expected1)
5282
5283 result2 = ar.argmax(skipna=False)
5284 if nanindex is not None and ar.dtype.kind != "O":
5285 expected2 = indarr.isel(x=nanindex, drop=True)
5286 expected2.attrs = self.attrs # Default keeps attrs for reduction operations
5287 else:
5288 expected2 = expected0
5289
5290 assert_identical(result2, expected2)
5291
5292 @pytest.mark.parametrize(
5293 "use_dask",

Callers

nothing calls this directly

Calls 5

argmaxMethod · 0.95
iselMethod · 0.95
assert_identicalFunction · 0.90
arangeMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected