-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Dataset.map #3459
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
Dataset.map #3459
Changes from all commits
7416ceb
1c495d3
46fa8cd
a44a59b
2529cf5
3cbce81
03e3ec9
583bc2a
8f2c990
9304cf0
d827794
fa57466
5da5fb2
5200383
4103380
1830d0a
9e1440f
0887359
3fc62dd
609cb5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3557,6 +3557,11 @@ def drop(self, labels=None, dim=None, *, errors="raise", **labels_kwargs): | |
"""Backward compatible method based on `drop_vars` and `drop_sel` | ||
|
||
Using either `drop_vars` or `drop_sel` is encouraged | ||
|
||
See Also | ||
-------- | ||
Dataset.drop_vars | ||
Dataset.drop_sel | ||
""" | ||
if errors not in ["raise", "ignore"]: | ||
raise ValueError('errors must be either "raise" or "ignore"') | ||
|
@@ -4108,14 +4113,14 @@ def reduce( | |
variables, coord_names=coord_names, attrs=attrs, indexes=indexes | ||
) | ||
|
||
def apply( | ||
def map( | ||
self, | ||
func: Callable, | ||
keep_attrs: bool = None, | ||
args: Iterable[Any] = (), | ||
**kwargs: Any, | ||
) -> "Dataset": | ||
"""Apply a function over the data variables in this dataset. | ||
"""Apply a function to each variable in this dataset | ||
|
||
Parameters | ||
---------- | ||
|
@@ -4135,7 +4140,7 @@ def apply( | |
Returns | ||
------- | ||
applied : Dataset | ||
Resulting dataset from applying ``func`` over each data variable. | ||
Resulting dataset from applying ``func`` to each data variable. | ||
|
||
Examples | ||
-------- | ||
|
@@ -4148,7 +4153,7 @@ def apply( | |
Data variables: | ||
foo (dim_0, dim_1) float64 -0.3751 -1.951 -1.945 0.2948 0.711 -0.3948 | ||
bar (x) int64 -1 2 | ||
>>> ds.apply(np.fabs) | ||
>>> ds.map(np.fabs) | ||
<xarray.Dataset> | ||
Dimensions: (dim_0: 2, dim_1: 3, x: 2) | ||
Dimensions without coordinates: dim_0, dim_1, x | ||
|
@@ -4165,6 +4170,27 @@ def apply( | |
attrs = self.attrs if keep_attrs else None | ||
return type(self)(variables, attrs=attrs) | ||
|
||
def apply( | ||
self, | ||
func: Callable, | ||
keep_attrs: bool = None, | ||
args: Iterable[Any] = (), | ||
**kwargs: Any, | ||
) -> "Dataset": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we keep the docstring here, even if it's just "Alias for Dataset.map"? Ideally we would use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also added |
||
""" | ||
Backward compatible implementation of ``map`` | ||
|
||
See Also | ||
-------- | ||
Dataset.map | ||
""" | ||
warnings.warn( | ||
"Dataset.apply may be deprecated in the future. Using Dataset.map is encouraged", | ||
PendingDeprecationWarning, | ||
stacklevel=2, | ||
) | ||
return self.map(func, keep_attrs, args, **kwargs) | ||
|
||
def assign( | ||
self, variables: Mapping[Hashable, Any] = None, **variables_kwargs: Hashable | ||
) -> "Dataset": | ||
|
Uh oh!
There was an error while loading. Please reload this page.