Skip to content

make more args kw only (except 'dim') #6403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2188,6 +2188,7 @@ def stack(
def unstack(
self,
dim: Hashable | Sequence[Hashable] | None = None,
*,
fill_value: Any = dtypes.NA,
sparse: bool = False,
) -> DataArray:
Expand Down Expand Up @@ -2462,7 +2463,9 @@ def drop_isel(self, indexers=None, **indexers_kwargs):
dataset = dataset.drop_isel(indexers=indexers, **indexers_kwargs)
return self._from_temp_dataset(dataset)

def dropna(self, dim: Hashable, how: str = "any", thresh: int = None) -> DataArray:
def dropna(
self, dim: Hashable, *, how: str = "any", thresh: int = None
) -> DataArray:
"""Returns a new array with dropped labels for missing values along
the provided dimension.

Expand Down Expand Up @@ -3210,7 +3213,9 @@ def _title_for_slice(self, truncate: int = 50) -> str:

return title

def diff(self, dim: Hashable, n: int = 1, label: Hashable = "upper") -> DataArray:
def diff(
self, dim: Hashable, *, n: int = 1, label: Hashable = "upper"
) -> DataArray:
"""Calculate the n-th order discrete difference along given axis.

Parameters
Expand Down Expand Up @@ -3483,6 +3488,7 @@ def quantile(
self,
q: ArrayLike,
dim: str | Sequence[Hashable] | None = None,
*,
method: QUANTILE_METHODS = "linear",
keep_attrs: bool = None,
skipna: bool = None,
Expand Down Expand Up @@ -3599,7 +3605,7 @@ def quantile(
return self._from_temp_dataset(ds)

def rank(
self, dim: Hashable, pct: bool = False, keep_attrs: bool = None
self, dim: Hashable, *, pct: bool = False, keep_attrs: bool = None
) -> DataArray:
"""Ranks the data.

Expand Down Expand Up @@ -4169,6 +4175,7 @@ def pad(
def idxmin(
self,
dim: Hashable = None,
*,
skipna: bool = None,
fill_value: Any = dtypes.NA,
keep_attrs: bool = None,
Expand Down Expand Up @@ -4265,6 +4272,7 @@ def idxmin(
def idxmax(
self,
dim: Hashable = None,
*,
skipna: bool = None,
fill_value: Any = dtypes.NA,
keep_attrs: bool = None,
Expand Down Expand Up @@ -4361,6 +4369,7 @@ def idxmax(
def argmin(
self,
dim: Hashable | Sequence[Hashable] = None,
*,
axis: int = None,
keep_attrs: bool = None,
skipna: bool = None,
Expand Down Expand Up @@ -4464,6 +4473,7 @@ def argmin(
def argmax(
self,
dim: Hashable | Sequence[Hashable] = None,
*,
axis: int = None,
keep_attrs: bool = None,
skipna: bool = None,
Expand Down Expand Up @@ -4720,6 +4730,7 @@ def curvefit(
def drop_duplicates(
self,
dim: Hashable | Iterable[Hashable] | ...,
*,
keep: Literal["first", "last"] | Literal[False] = "first",
):
"""Returns a new DataArray with duplicate dimension values removed.
Expand All @@ -4730,6 +4741,7 @@ def drop_duplicates(
Pass `...` to drop duplicates along all dimensions.
keep : {"first", "last", False}, default: "first"
Determines which duplicates (if any) to keep.

- ``"first"`` : Drop duplicates except for the first occurrence.
- ``"last"`` : Drop duplicates except for the last occurrence.
- False : Drop all duplicates.
Expand Down
12 changes: 10 additions & 2 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3514,6 +3514,7 @@ def swap_dims(
def expand_dims(
self,
dim: None | Hashable | Sequence[Hashable] | Mapping[Any, Any] = None,
*,
axis: None | int | Sequence[int] = None,
**dim_kwargs: Any,
) -> Dataset:
Expand Down Expand Up @@ -3789,6 +3790,7 @@ def set_index(
def reset_index(
self,
dims_or_levels: Hashable | Sequence[Hashable],
*,
drop: bool = False,
) -> Dataset:
"""Reset the specified index(es) or multi-index level(s).
Expand Down Expand Up @@ -4272,6 +4274,7 @@ def _unstack_full_reindex(
def unstack(
self,
dim: Hashable | Iterable[Hashable] = None,
*,
fill_value: Any = dtypes.NA,
sparse: bool = False,
) -> Dataset:
Expand Down Expand Up @@ -4818,6 +4821,7 @@ def transpose(
def dropna(
self,
dim: Hashable,
*,
how: str = "any",
thresh: int = None,
subset: Iterable[Hashable] = None,
Expand Down Expand Up @@ -5995,7 +5999,7 @@ def _copy_attrs_from(self, other):
if v in self.variables:
self.variables[v].attrs = other.variables[v].attrs

def diff(self, dim, n=1, label="upper"):
def diff(self, dim, *, n=1, label="upper"):
"""Calculate the n-th order discrete difference along given axis.

Parameters
Expand Down Expand Up @@ -6317,6 +6321,7 @@ def quantile(
self,
q: ArrayLike,
dim: str | Iterable[Hashable] | None = None,
*,
method: QUANTILE_METHODS = "linear",
numeric_only: bool = False,
keep_attrs: bool = None,
Expand Down Expand Up @@ -6491,7 +6496,7 @@ def quantile(
)
return new.assign_coords(quantile=q)

def rank(self, dim, pct=False, keep_attrs=None):
def rank(self, dim, *, pct=False, keep_attrs=None):
"""Ranks the data.

Equal values are assigned a rank that is the average of the ranks that
Expand Down Expand Up @@ -7392,6 +7397,7 @@ def pad(
def idxmin(
self,
dim: Hashable = None,
*,
skipna: bool = None,
fill_value: Any = dtypes.NA,
keep_attrs: bool = None,
Expand Down Expand Up @@ -7489,6 +7495,7 @@ def idxmin(
def idxmax(
self,
dim: Hashable = None,
*,
skipna: bool = None,
fill_value: Any = dtypes.NA,
keep_attrs: bool = None,
Expand Down Expand Up @@ -7972,6 +7979,7 @@ def _wrapper(Y, *coords_, **kwargs):
def drop_duplicates(
self,
dim: Hashable | Iterable[Hashable] | ...,
*,
keep: Literal["first", "last"] | Literal[False] = "first",
):
"""Returns a new Dataset with duplicate dimension values removed.
Expand Down
1 change: 1 addition & 0 deletions xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ def quantile(
self,
q,
dim=None,
*,
method="linear",
keep_attrs=None,
skipna=None,
Expand Down
6 changes: 6 additions & 0 deletions xarray/core/weighted.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def _implementation(self, func, dim, **kwargs):
def sum_of_weights(
self,
dim: Hashable | Iterable[Hashable] | None = None,
*,
keep_attrs: bool | None = None,
) -> T_Xarray:

Expand All @@ -258,6 +259,7 @@ def sum_of_weights(
def sum_of_squares(
self,
dim: Hashable | Iterable[Hashable] | None = None,
*,
skipna: bool | None = None,
keep_attrs: bool | None = None,
) -> T_Xarray:
Expand All @@ -269,6 +271,7 @@ def sum_of_squares(
def sum(
self,
dim: Hashable | Iterable[Hashable] | None = None,
*,
skipna: bool | None = None,
keep_attrs: bool | None = None,
) -> T_Xarray:
Expand All @@ -280,6 +283,7 @@ def sum(
def mean(
self,
dim: Hashable | Iterable[Hashable] | None = None,
*,
skipna: bool | None = None,
keep_attrs: bool | None = None,
) -> T_Xarray:
Expand All @@ -291,6 +295,7 @@ def mean(
def var(
self,
dim: Hashable | Iterable[Hashable] | None = None,
*,
skipna: bool | None = None,
keep_attrs: bool | None = None,
) -> T_Xarray:
Expand All @@ -302,6 +307,7 @@ def var(
def std(
self,
dim: Hashable | Iterable[Hashable] | None = None,
*,
skipna: bool | None = None,
keep_attrs: bool | None = None,
) -> T_Xarray:
Expand Down