Add sel_points for point-wise indexing by label#507
Conversation
There was a problem hiding this comment.
I know these bullets are straight from pandas but "default" isn't a valid keyword here. I think this may be clearer as * None (default): only exact matches.
|
This looks pretty good to me. Are you basically letting pandas do all the testing in terms of the |
This has been my strategy. Pandas has lots of tests for the exact behavior of |
xref GH475
Example usage:
In [1]: da = xray.DataArray(np.arange(56).reshape((7, 8)),
...: coords={'x': list('abcdefg'),
...: 'y': 10 * np.arange(8)},
...: dims=['x', 'y'])
...:
In [2]: da
Out[2]:
<xray.DataArray (x: 7, y: 8)>
array([[ 0, 1, 2, 3, 4, 5, 6, 7],
[ 8, 9, 10, 11, 12, 13, 14, 15],
[16, 17, 18, 19, 20, 21, 22, 23],
[24, 25, 26, 27, 28, 29, 30, 31],
[32, 33, 34, 35, 36, 37, 38, 39],
[40, 41, 42, 43, 44, 45, 46, 47],
[48, 49, 50, 51, 52, 53, 54, 55]])
Coordinates:
* y (y) int64 0 10 20 30 40 50 60 70
* x (x) |S1 'a' 'b' 'c' 'd' 'e' 'f' 'g'
# we can index by position along each dimension
In [3]: da.isel_points(x=[0, 1, 6], y=[0, 1, 0], dim='points')
Out[3]:
<xray.DataArray (points: 3)>
array([ 0, 9, 48])
Coordinates:
y (points) int64 0 10 0
x (points) |S1 'a' 'b' 'g'
* points (points) int64 0 1 2
# or equivalently by label
In [4]: da.sel_points(x=['a', 'b', 'g'], y=[0, 10, 0], dim='points')
Out[4]:
<xray.DataArray (points: 3)>
array([ 0, 9, 48])
Coordinates:
y (points) int64 0 10 0
x (points) |S1 'a' 'b' 'g'
* points (points) int64 0 1 2
Bug fixes
cc jhamman
|
@jhamman any other comments? If not, I'll merge this shortly. |
|
No, I think this is good to go. |
|
Are there going to be merge conflicts with #512? Maybe merge this then update that PR accordingly? |
Add sel_points for point-wise indexing by label
| actual = da.isel_points(y=[1, 2], x=[1, 2], dim=['A', 'B']) | ||
| assert 'points' in actual.coords | ||
|
|
||
| def test_isel_points(self): |
There was a problem hiding this comment.
you have two test methods with the same name
xref #475
Example usage:
cc @jhamman