-
-
Notifications
You must be signed in to change notification settings - Fork 403
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
Add .iloc and .ndloc integer indexing methods for Datasets #1435
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3b9b4ea
Small fix for auto-indexing
philippjfr c2bc41b
Added iloc tabular indexing interface
philippjfr 48d7a06
Small docstring improvements
philippjfr ddff785
Updated Point selection example to use .iloc
philippjfr 0fcf161
Renamed TabularIndex object to iloc
philippjfr c93995c
Added ndloc indexing interface
philippjfr 0d2a9c1
Implemented Image indexing using ndloc
philippjfr 969c06c
Implemented Image.sample on top of ndloc interface
philippjfr 2b72785
Fixed bug in Dataset unit test setup
philippjfr 9638fb8
Fixed closest bug in Image.sample
philippjfr 0da749b
Fixed Image.sample y-coord index
philippjfr 4af6c8c
Minor fixes for sampling
philippjfr 3f5ba05
Added Image sampling test
philippjfr 788cea8
Small fix for ndloc
philippjfr bdf2ad3
Vectorized Image.sample
philippjfr 6571609
Added ndloc unit tests
philippjfr 8607c20
Simplified decimate operation using iloc
philippjfr 922accd
Use iloc in Tabular.pprint_cell
philippjfr 5a1d930
Improved iloc and ndloc docstrings
philippjfr 3ecff25
Small docstring fixes for iloc and ndloc
philippjfr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
|
||
from .. import util | ||
from ..element import Element | ||
from ..ndmapping import NdMapping, item_check | ||
from ..ndmapping import NdMapping, item_check, OrderedDict | ||
from .interface import Interface | ||
from .pandas import PandasInterface | ||
|
||
|
@@ -241,6 +241,30 @@ def dframe(cls, columns, dimensions): | |
def nonzero(cls, dataset): | ||
return True | ||
|
||
@classmethod | ||
def iloc(cls, dataset, index): | ||
""" | ||
Dask does not support iloc, therefore iloc will execute | ||
the call graph and lose the laziness of the operation. | ||
""" | ||
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. I wonder if there could be optional performance warnings we could issue when laziness is lost. Not for this PR though. |
||
rows, cols = index | ||
scalar = False | ||
if isinstance(cols, slice): | ||
cols = [d.name for d in dataset.dimensions()][cols] | ||
elif np.isscalar(cols): | ||
scalar = np.isscalar(rows) | ||
cols = [dataset.get_dimension(cols).name] | ||
else: | ||
cols = [dataset.get_dimension(d).name for d in index[1]] | ||
if np.isscalar(rows): | ||
rows = [rows] | ||
|
||
data = OrderedDict() | ||
for c in cols: | ||
data[c] = dataset.data[c].compute().iloc[rows].values | ||
if scalar: | ||
return data[cols[0]][0] | ||
return tuple(data.values()) | ||
|
||
|
||
Interface.register(DaskInterface) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was left over from when we returned tuples when indexing RGBs, so I ended up updating it, suppose
rgb_parrot[0, 0, 'R']
would have been clearer but we're probably throwing this notebook out right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right.