Skip to content

Commit b891f94

Browse files
committed
remove axis argument and some unit test cleanups
1 parent 4b0f4e3 commit b891f94

File tree

4 files changed

+192
-205
lines changed

4 files changed

+192
-205
lines changed

xarray/core/computation.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,6 @@ def _calc_idxminmax(
13141314
array,
13151315
func: Callable,
13161316
dim: Optional[Hashable],
1317-
axis: Optional[int],
13181317
skipna: Optional[bool],
13191318
promote: Optional[bool],
13201319
keep_attrs: Optional[bool],
@@ -1327,21 +1326,15 @@ def _calc_idxminmax(
13271326

13281327
if dim is not None:
13291328
pass # Use the dim if available
1330-
elif axis is not None:
1331-
dim = array.dims[axis]
13321329
elif array.ndim == 1:
13331330
# it is okay to guess the dim if there is only 1
13341331
dim = array.dims[0]
13351332
else:
13361333
# The dim is not specified and ambiguous. Don't guess.
1337-
raise ValueError(
1338-
"Must supply either 'dim' or 'axis' argument " "for multidimensional arrays"
1339-
)
1334+
raise ValueError("Must supply 'dim' argument for multidimensional arrays")
13401335

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

xarray/core/dataarray.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -3433,7 +3433,6 @@ def pad(
34333433
def idxmin(
34343434
self,
34353435
dim: Hashable = None,
3436-
axis: int = None,
34373436
skipna: bool = None,
34383437
promote: bool = None,
34393438
keep_attrs: Optional[bool] = False,
@@ -3451,10 +3450,8 @@ def idxmin(
34513450
Parameters
34523451
----------
34533452
dim : str, optional
3454-
Dimension over which to apply `idxmin`.
3455-
axis : int, optional
3456-
Axis(es) over which to repeatedly apply `idxmin`. Exactly one of
3457-
the 'dim' and 'axis' arguments must be supplied.
3453+
Dimension over which to apply `idxmin`. This is optional for 1D
3454+
arrays, but required for arrays with 2 or more dimensions.
34583455
skipna : bool or None, default None
34593456
If True, skip missing values (as marked by NaN). By default, only
34603457
skips missing values for float dtypes; other dtypes either do not
@@ -3525,7 +3522,6 @@ def idxmin(
35253522
array=self,
35263523
func=lambda x, *args, **kwargs: x.argmin(*args, **kwargs),
35273524
dim=dim,
3528-
axis=axis,
35293525
skipna=skipna,
35303526
promote=promote,
35313527
keep_attrs=keep_attrs,
@@ -3535,7 +3531,6 @@ def idxmin(
35353531
def idxmax(
35363532
self,
35373533
dim: Hashable = None,
3538-
axis: int = None,
35393534
skipna: bool = None,
35403535
promote: bool = None,
35413536
keep_attrs: Optional[bool] = False,
@@ -3553,10 +3548,8 @@ def idxmax(
35533548
Parameters
35543549
----------
35553550
dim : str, optional
3556-
Dimension over which to apply `idxmax`..
3557-
axis : int, optional
3558-
Axis(es) over which to repeatedly apply `idxmax`. Exactly one of
3559-
the 'dim' and 'axis' arguments must be supplied.
3551+
Dimension over which to apply `idxmax`. This is optional for 1D
3552+
arrays, but required for arrays with 2 or more dimensions.
35603553
skipna : bool or None, default None
35613554
If True, skip missing values (as marked by NaN). By default, only
35623555
skips missing values for float dtypes; other dtypes either do not
@@ -3627,7 +3620,6 @@ def idxmax(
36273620
array=self,
36283621
func=lambda x, *args, **kwargs: x.argmax(*args, **kwargs),
36293622
dim=dim,
3630-
axis=axis,
36313623
skipna=skipna,
36323624
promote=promote,
36333625
keep_attrs=keep_attrs,

xarray/core/dataset.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -5924,7 +5924,6 @@ def pad(
59245924
def idxmin(
59255925
self,
59265926
dim: Hashable = None,
5927-
axis: int = None,
59285927
skipna: bool = None,
59295928
promote: bool = None,
59305929
keep_attrs: bool = False,
@@ -5942,10 +5941,8 @@ def idxmin(
59425941
Parameters
59435942
----------
59445943
dim : str, optional
5945-
Dimension over which to apply `idxmin`.
5946-
axis : int, optional
5947-
Axis(es) over which to repeatedly apply `idxmin`. Exactly one of
5948-
the 'dim' and 'axis' arguments must be supplied.
5944+
Dimension over which to apply `idxmin`. This is optional for 1D
5945+
variables, but required for variables with 2 or more dimensions.
59495946
skipna : bool or None, default None
59505947
If True, skip missing values (as marked by NaN). By default, only
59515948
skips missing values for float dtypes; other dtypes either do not
@@ -6015,7 +6012,6 @@ def idxmin(
60156012
return self.map(
60166013
"idxmin",
60176014
dim=dim,
6018-
axis=axis,
60196015
skipna=skipna,
60206016
promote=promote,
60216017
keep_attrs=keep_attrs,
@@ -6025,7 +6021,6 @@ def idxmin(
60256021
def idxmax(
60266022
self,
60276023
dim: Hashable = None,
6028-
axis: int = None,
60296024
skipna: bool = None,
60306025
promote: bool = None,
60316026
keep_attrs: Optional[bool] = False,
@@ -6043,10 +6038,8 @@ def idxmax(
60436038
Parameters
60446039
----------
60456040
dim : str, optional
6046-
Dimension over which to apply `idxmax`.
6047-
axis : int, optional
6048-
Axis(es) over which to repeatedly apply `idxmax`. Exactly one of
6049-
the 'dim' and 'axis' arguments must be supplied.
6041+
Dimension over which to apply `idxmax`. This is optional for 1D
6042+
variables, but required for variables with 2 or more dimensions.
60506043
skipna : bool or None, default None
60516044
If True, skip missing values (as marked by NaN). By default, only
60526045
skips missing values for float dtypes; other dtypes either do not
@@ -6078,7 +6071,6 @@ def idxmax(
60786071
return self.map(
60796072
"idxmax",
60806073
dim=dim,
6081-
axis=axis,
60826074
skipna=skipna,
60836075
promote=promote,
60846076
keep_attrs=keep_attrs,

0 commit comments

Comments
 (0)