MCPcopy Index your code
hub / github.com/pydata/xarray / test_argmin

Method test_argmin

xarray/tests/test_dataarray.py:5217–5251  ·  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

5215 "ignore:Behaviour of argmin/argmax with neither dim nor :FutureWarning"
5216 )
5217 def test_argmin(
5218 self,
5219 x: np.ndarray,
5220 minindex: int | float,
5221 maxindex: int | float,
5222 nanindex: int | None,
5223 ) -> None:
5224 ar = xr.DataArray(
5225 x, dims=["x"], coords={"x": np.arange(x.size) * 4}, attrs=self.attrs
5226 )
5227 indarr = xr.DataArray(np.arange(x.size, dtype=np.intp), dims=["x"])
5228
5229 if np.isnan(minindex):
5230 with pytest.raises(ValueError):
5231 ar.argmin()
5232 return
5233
5234 expected0 = indarr[minindex]
5235 expected0.attrs = self.attrs # argmin should preserve attrs from input
5236 result0 = ar.argmin()
5237 assert_identical(result0, expected0)
5238
5239 result1 = ar.argmin(keep_attrs=True)
5240 expected1 = expected0.copy()
5241 expected1.attrs = self.attrs
5242 assert_identical(result1, expected1)
5243
5244 result2 = ar.argmin(skipna=False)
5245 if nanindex is not None and ar.dtype.kind != "O":
5246 expected2 = indarr.isel(x=nanindex, drop=True)
5247 expected2.attrs = self.attrs # Default keeps attrs for reduction operations
5248 else:
5249 expected2 = expected0
5250
5251 assert_identical(result2, expected2)
5252
5253 @pytest.mark.filterwarnings(
5254 "ignore:Behaviour of argmin/argmax with neither dim nor :FutureWarning"

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected