Skip to content

Commit

Permalink
remove axis argument and some unit test cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
toddrjen committed Mar 22, 2020
1 parent 4b0f4e3 commit b891f94
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 205 deletions.
9 changes: 1 addition & 8 deletions xarray/core/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,6 @@ def _calc_idxminmax(
array,
func: Callable,
dim: Optional[Hashable],
axis: Optional[int],
skipna: Optional[bool],
promote: Optional[bool],
keep_attrs: Optional[bool],
Expand All @@ -1327,21 +1326,15 @@ def _calc_idxminmax(

if dim is not None:
pass # Use the dim if available
elif axis is not None:
dim = array.dims[axis]
elif array.ndim == 1:
# it is okay to guess the dim if there is only 1
dim = array.dims[0]
else:
# The dim is not specified and ambiguous. Don't guess.
raise ValueError(
"Must supply either 'dim' or 'axis' argument " "for multidimensional arrays"
)
raise ValueError("Must supply 'dim' argument for multidimensional arrays")

if dim in array.coords:
pass # This is okay
elif axis is not None:
raise IndexError(f'Axis "{axis}" does not have coordinates')
else:
raise KeyError(f'Dimension "{dim}" does not have coordinates')

Expand Down
16 changes: 4 additions & 12 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3433,7 +3433,6 @@ def pad(
def idxmin(
self,
dim: Hashable = None,
axis: int = None,
skipna: bool = None,
promote: bool = None,
keep_attrs: Optional[bool] = False,
Expand All @@ -3451,10 +3450,8 @@ def idxmin(
Parameters
----------
dim : str, optional
Dimension over which to apply `idxmin`.
axis : int, optional
Axis(es) over which to repeatedly apply `idxmin`. Exactly one of
the 'dim' and 'axis' arguments must be supplied.
Dimension over which to apply `idxmin`. This is optional for 1D
arrays, but required for arrays with 2 or more dimensions.
skipna : bool or None, default None
If True, skip missing values (as marked by NaN). By default, only
skips missing values for float dtypes; other dtypes either do not
Expand Down Expand Up @@ -3525,7 +3522,6 @@ def idxmin(
array=self,
func=lambda x, *args, **kwargs: x.argmin(*args, **kwargs),
dim=dim,
axis=axis,
skipna=skipna,
promote=promote,
keep_attrs=keep_attrs,
Expand All @@ -3535,7 +3531,6 @@ def idxmin(
def idxmax(
self,
dim: Hashable = None,
axis: int = None,
skipna: bool = None,
promote: bool = None,
keep_attrs: Optional[bool] = False,
Expand All @@ -3553,10 +3548,8 @@ def idxmax(
Parameters
----------
dim : str, optional
Dimension over which to apply `idxmax`..
axis : int, optional
Axis(es) over which to repeatedly apply `idxmax`. Exactly one of
the 'dim' and 'axis' arguments must be supplied.
Dimension over which to apply `idxmax`. This is optional for 1D
arrays, but required for arrays with 2 or more dimensions.
skipna : bool or None, default None
If True, skip missing values (as marked by NaN). By default, only
skips missing values for float dtypes; other dtypes either do not
Expand Down Expand Up @@ -3627,7 +3620,6 @@ def idxmax(
array=self,
func=lambda x, *args, **kwargs: x.argmax(*args, **kwargs),
dim=dim,
axis=axis,
skipna=skipna,
promote=promote,
keep_attrs=keep_attrs,
Expand Down
16 changes: 4 additions & 12 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5924,7 +5924,6 @@ def pad(
def idxmin(
self,
dim: Hashable = None,
axis: int = None,
skipna: bool = None,
promote: bool = None,
keep_attrs: bool = False,
Expand All @@ -5942,10 +5941,8 @@ def idxmin(
Parameters
----------
dim : str, optional
Dimension over which to apply `idxmin`.
axis : int, optional
Axis(es) over which to repeatedly apply `idxmin`. Exactly one of
the 'dim' and 'axis' arguments must be supplied.
Dimension over which to apply `idxmin`. This is optional for 1D
variables, but required for variables with 2 or more dimensions.
skipna : bool or None, default None
If True, skip missing values (as marked by NaN). By default, only
skips missing values for float dtypes; other dtypes either do not
Expand Down Expand Up @@ -6015,7 +6012,6 @@ def idxmin(
return self.map(
"idxmin",
dim=dim,
axis=axis,
skipna=skipna,
promote=promote,
keep_attrs=keep_attrs,
Expand All @@ -6025,7 +6021,6 @@ def idxmin(
def idxmax(
self,
dim: Hashable = None,
axis: int = None,
skipna: bool = None,
promote: bool = None,
keep_attrs: Optional[bool] = False,
Expand All @@ -6043,10 +6038,8 @@ def idxmax(
Parameters
----------
dim : str, optional
Dimension over which to apply `idxmax`.
axis : int, optional
Axis(es) over which to repeatedly apply `idxmax`. Exactly one of
the 'dim' and 'axis' arguments must be supplied.
Dimension over which to apply `idxmax`. This is optional for 1D
variables, but required for variables with 2 or more dimensions.
skipna : bool or None, default None
If True, skip missing values (as marked by NaN). By default, only
skips missing values for float dtypes; other dtypes either do not
Expand Down Expand Up @@ -6078,7 +6071,6 @@ def idxmax(
return self.map(
"idxmax",
dim=dim,
axis=axis,
skipna=skipna,
promote=promote,
keep_attrs=keep_attrs,
Expand Down
Loading

0 comments on commit b891f94

Please sign in to comment.