Skip to content
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

Docstring examples #7881

Merged
merged 35 commits into from Jul 4, 2023
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
70c52b8
add examples
harshitha1201 May 29, 2023
1e403a8
changes done to dataset.isel
harshitha1201 Jun 5, 2023
431f8b7
Changes done on isel and reduce
harshitha1201 Jun 12, 2023
ee8ba41
xarray.dataset.tail
harshitha1201 Jun 20, 2023
82e1161
xarray.dataset.head
harshitha1201 Jun 20, 2023
760aa4a
xarray.dataset.dropna
harshitha1201 Jun 20, 2023
848a5fd
xarray.dataset.ffill
harshitha1201 Jun 20, 2023
eb7514e
xarray.dataset.bfill
harshitha1201 Jun 20, 2023
5ecfd63
xarray.dataset.set_Coords
harshitha1201 Jun 20, 2023
7575a12
xarray.dataset.reset_coords
harshitha1201 Jun 20, 2023
14952fa
Revert "xarray.dataset.reset_coords"
harshitha1201 Jun 22, 2023
3869b78
Revert "xarray.dataset.tail"
harshitha1201 Jun 22, 2023
212c874
Revert "xarray.dataset.head"
harshitha1201 Jun 22, 2023
05c9e66
Revert "xarray.dataset.dropna"
harshitha1201 Jun 22, 2023
4ee8603
Revert "xarray.dataset.ffill"
harshitha1201 Jun 22, 2023
95e27d2
Revert "xarray.dataset.bfill"
harshitha1201 Jun 22, 2023
4811641
Revert "xarray.dataset.set_Coords"
harshitha1201 Jun 22, 2023
20ac818
check pre-commit
harshitha1201 Jun 27, 2023
eae0ae9
changes
harshitha1201 Jun 30, 2023
39880aa
Merge branch 'main' into add-examples
harshitha1201 Jun 30, 2023
0a1a558
argmin_indices
harshitha1201 Jun 30, 2023
c4988b6
Merge branch 'add-examples' of https://github.com/harshitha1201/xarra…
harshitha1201 Jun 30, 2023
6a5bc79
Try adding blank lines
TomNicholas Jun 30, 2023
1ee2c93
indentation change
harshitha1201 Jun 30, 2023
7872104
Merge branch 'add-examples' of https://github.com/harshitha1201/xarra…
harshitha1201 Jun 30, 2023
a5ea816
indentation
harshitha1201 Jun 30, 2023
1be4f82
removed dataset.reduce 'skew' example
harshitha1201 Jul 3, 2023
067a310
doctests
harshitha1201 Jul 3, 2023
460021b
change
harshitha1201 Jul 3, 2023
d60d601
argmin
harshitha1201 Jul 3, 2023
85d3817
Update xarray/core/dataset.py
harshitha1201 Jul 3, 2023
b781f6a
Merge branch 'main' into add-examples
harshitha1201 Jul 3, 2023
4ed9393
what's new.rst updated
harshitha1201 Jul 3, 2023
ade5bb8
Merge branch 'add-examples' of https://github.com/harshitha1201/xarra…
harshitha1201 Jul 3, 2023
42a7cee
Move whatsnew entry to unreleased version
TomNicholas Jul 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
118 changes: 118 additions & 0 deletions xarray/core/dataset.py
Expand Up @@ -2486,6 +2486,35 @@ def isel(
in this dataset, unless vectorized indexing was triggered by using
an array indexer, in which case the data will be a copy.

Example
harshitha1201 marked this conversation as resolved.
Show resolved Hide resolved
-------

import xarray as xr

dataset = xr.Dataset(
{
'math_scores': (
['student', 'test'],
[[90, 85, 92],
[78, 80, 85],
[95, 92, 98]]
),
'english_scores': (
['student', 'test'],
[[88, 90, 92],
[75, 82, 79],
[93, 96, 91]]
)
},
coords={
'student': ['Alice', 'Bob', 'Charlie'],
'test': ['Test 1', 'Test 2', 'Test 3']
}
)

second_student_first_test = dataset.isel(student=1, test=0)
harshitha1201 marked this conversation as resolved.
Show resolved Hide resolved
print(second_student_first_test)
harshitha1201 marked this conversation as resolved.
Show resolved Hide resolved

See Also
--------
Dataset.sel
Expand Down Expand Up @@ -5911,6 +5940,38 @@ def reduce(
reduced : Dataset
Dataset with this object's DataArrays replaced with new DataArrays
of summarized data and the indicated dimension(s) removed.

Example
-------

import xarray as xr
import numpy as np

dataset = xr.Dataset(
{
'math_scores': (
['student', 'test'],
[[90, 85, 92],
[78, 80, 85],
[95, 92, 98]]
),
'english_scores': (
['student', 'test'],
[[88, 90, 92],
[75, 82, 79],
[93, 96, 91]]
)
},
coords={
'student': ['Alice', 'Bob', 'Charlie'],
'test': ['Test 1', 'Test 2', 'Test 3']
}
)

mean_scores = dataset.reduce(func=np.mean, dim='test')
harshitha1201 marked this conversation as resolved.
Show resolved Hide resolved

print(mean_scores)

"""
if kwargs.get("axis", None) is not None:
raise ValueError(
Expand Down Expand Up @@ -8424,6 +8485,36 @@ def argmin(self: T_Dataset, dim: Hashable | None = None, **kwargs) -> T_Dataset:
-------
result : Dataset

Example
-------

import xarray as xr

dataset = xr.Dataset(
{
'math_scores': (
['student', 'test'],
[[90, 85, 79],
[78, 80, 85],
[95, 92, 98]]
),
'english_scores': (
['student', 'test'],
[[88, 80, 92],
[75, 95, 79],
[93, 96, 78]]
)
},
coords={
'student': ['Alice', 'Bob', 'Charlie'],
'test': ['Test 1', 'Test 2', 'Test 3']
}
)

argmin_indices = dataset.argmin(dim='student')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can add text explaining this

Can also feed the resulting indexes back in to .isel (that's why this argmin method exists)

Might be good to think of other example datasets for which you would be really interested in the index.


print(argmin_indices)

See Also
--------
DataArray.argmin
harshitha1201 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -8483,6 +8574,33 @@ def argmax(self: T_Dataset, dim: Hashable | None = None, **kwargs) -> T_Dataset:
-------
result : Dataset

Example
-------

dataset = xr.Dataset(
{
'math_scores': (
['student', 'test'],
[[90, 85, 92],
[78, 80, 85],
[95, 92, 98]]
),
'english_scores': (
['student', 'test'],
[[88, 90, 92],
[75, 82, 79],
[93, 96, 91]]
)
},
coords={
'student': ['Alice', 'Bob', 'Charlie'],
'test': ['Test 1', 'Test 2', 'Test 3']
}
)
argmax_indices = dataset.argmax(dim='test')

print(argmax_indices)

See Also
--------
DataArray.argmax
Expand Down