Skip to content

Commit

Permalink
delegate more to other existing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
toddrjen committed Mar 27, 2020
1 parent c896135 commit 51e4926
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
13 changes: 7 additions & 6 deletions xarray/core/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,9 +1346,9 @@ def _calc_idxminmax(
array,
func: Callable,
dim: Optional[Hashable],
skipna: Optional[bool],
skipna: bool = None,
fill_value: Any = None,
keep_attrs: Optional[bool],
keep_attrs: bool = None,
**kwargs: Any,
):
"""Apply common operations for idxmin and idxmax."""
Expand Down Expand Up @@ -1379,7 +1379,9 @@ def _calc_idxminmax(
array = array.where(~allna, 0)

# This will run argmin or argmax.
indx = func(array, dim=dim, axis=None, keep_attrs=False, skipna=skipna, **kwargs)
indx = func(
array, dim=dim, axis=None, keep_attrs=keep_attrs, skipna=skipna, **kwargs
)

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

# Put the attrs back in if needed
if keep_attrs:
res.attrs = array.attrs
# Copy attributes from argmin/argmax, if any
res.attrs = indx.attrs

return res
8 changes: 4 additions & 4 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3512,8 +3512,8 @@ def idxmin(
self,
dim: Hashable = None,
skipna: bool = None,
fill_value: Any = np.NaN,
keep_attrs: Optional[bool] = False,
fill_value: Any = dtypes.NA,
keep_attrs: bool = None,
**kwargs: Any,
) -> "DataArray":
"""Return the coordinate of the minimum value along a dimension.
Expand Down Expand Up @@ -3610,8 +3610,8 @@ def idxmax(
self,
dim: Hashable = None,
skipna: bool = None,
fill_value: Any = np.NaN,
keep_attrs: Optional[bool] = False,
fill_value: Any = dtypes.NA,
keep_attrs: bool = None,
**kwargs: Any,
) -> "DataArray":
"""Return the coordinate of the maximum value along a dimension.
Expand Down
8 changes: 4 additions & 4 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6098,8 +6098,8 @@ def idxmin(
self,
dim: Hashable = None,
skipna: bool = None,
fill_value: Any = np.NaN,
keep_attrs: bool = False,
fill_value: Any = dtypes.NA,
keep_attrs: bool = None,
**kwargs: Any,
) -> "Dataset":
"""Return the coordinate of the minimum value along a dimension.
Expand Down Expand Up @@ -6197,8 +6197,8 @@ def idxmax(
self,
dim: Hashable = None,
skipna: bool = None,
fill_value: Any = np.NaN,
keep_attrs: Optional[bool] = False,
fill_value: Any = dtypes.NA,
keep_attrs: bool = None,
**kwargs: Any,
) -> "Dataset":
"""Return the coordinate of the maximum value along a dimension.
Expand Down

0 comments on commit 51e4926

Please sign in to comment.