Skip to content

Commit b7b8f6b

Browse files
committed
delegate more to other existing functions
1 parent 61ef76b commit b7b8f6b

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

xarray/core/computation.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1346,9 +1346,9 @@ def _calc_idxminmax(
13461346
array,
13471347
func: Callable,
13481348
dim: Optional[Hashable],
1349-
skipna: Optional[bool],
1349+
skipna: bool = None,
13501350
fill_value: Any = None,
1351-
keep_attrs: Optional[bool],
1351+
keep_attrs: bool = None,
13521352
**kwargs: Any,
13531353
):
13541354
"""Apply common operations for idxmin and idxmax."""
@@ -1379,7 +1379,9 @@ def _calc_idxminmax(
13791379
array = array.where(~allna, 0)
13801380

13811381
# This will run argmin or argmax.
1382-
indx = func(array, dim=dim, axis=None, keep_attrs=False, skipna=skipna, **kwargs)
1382+
indx = func(
1383+
array, dim=dim, axis=None, keep_attrs=keep_attrs, skipna=skipna, **kwargs
1384+
)
13831385

13841386
# Get the coordinate we want.
13851387
coordarray = array[dim]
@@ -1399,8 +1401,7 @@ def _calc_idxminmax(
13991401
# The dim is gone but we need to remove the corresponding coordinate.
14001402
del res.coords[dim]
14011403

1402-
# Put the attrs back in if needed
1403-
if keep_attrs:
1404-
res.attrs = array.attrs
1404+
# Copy attributes from argmin/argmax, if any
1405+
res.attrs = indx.attrs
14051406

14061407
return res

xarray/core/dataarray.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3512,8 +3512,8 @@ def idxmin(
35123512
self,
35133513
dim: Hashable = None,
35143514
skipna: bool = None,
3515-
fill_value: Any = np.NaN,
3516-
keep_attrs: Optional[bool] = False,
3515+
fill_value: Any = dtypes.NA,
3516+
keep_attrs: bool = None,
35173517
**kwargs: Any,
35183518
) -> "DataArray":
35193519
"""Return the coordinate of the minimum value along a dimension.
@@ -3610,8 +3610,8 @@ def idxmax(
36103610
self,
36113611
dim: Hashable = None,
36123612
skipna: bool = None,
3613-
fill_value: Any = np.NaN,
3614-
keep_attrs: Optional[bool] = False,
3613+
fill_value: Any = dtypes.NA,
3614+
keep_attrs: bool = None,
36153615
**kwargs: Any,
36163616
) -> "DataArray":
36173617
"""Return the coordinate of the maximum value along a dimension.

xarray/core/dataset.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -6098,8 +6098,8 @@ def idxmin(
60986098
self,
60996099
dim: Hashable = None,
61006100
skipna: bool = None,
6101-
fill_value: Any = np.NaN,
6102-
keep_attrs: bool = False,
6101+
fill_value: Any = dtypes.NA,
6102+
keep_attrs: bool = None,
61036103
**kwargs: Any,
61046104
) -> "Dataset":
61056105
"""Return the coordinate of the minimum value along a dimension.
@@ -6197,8 +6197,8 @@ def idxmax(
61976197
self,
61986198
dim: Hashable = None,
61996199
skipna: bool = None,
6200-
fill_value: Any = np.NaN,
6201-
keep_attrs: Optional[bool] = False,
6200+
fill_value: Any = dtypes.NA,
6201+
keep_attrs: bool = None,
62026202
**kwargs: Any,
62036203
) -> "Dataset":
62046204
"""Return the coordinate of the maximum value along a dimension.

0 commit comments

Comments
 (0)