-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Pass arbitrary options to sel() #7099
Comments
Another difficulty regarding multi-coordinate indexes: ideally options should be set per index, not per coordinate. |
Or we could simply decide that It would actually make sense to have something like |
another option would be to allow passing a custom object, like class Indexer:
def __init__(self, indexer, **options):
...
ds.sel(x=Indexer([0, 2], method="nearest")) I think we wanted to have something like that, anyways, to be able to specify other behaviors of a slice, like right-exclusive? |
Or use class Dataset:
def sel(
self,
indexers: Mapping[Any, Any] | Indexer | Iterable[Indexer],
**indexers_kwargs: Any,
):
...
class Indexer:
def __init__(self, labels=None, options=None, **label_kwargs):
... Let's assume a Dataset with indexers = [
Indexer(lon=[2, 15], lat=[45, 48], options={"foo": "bar"}),
Indexer(time="2022-01-01"),
]
ds.sel(indexers) This could also be used to avoid code duplication when using common selection options for different indexes. |
Is your feature request related to a problem?
Currently
.sel()
accepts two optionsmethod
andtolerance
. These are relevant for default (pandas) indexes but not necessarily for other, custom indexes.It would be also useful for custom indexes to expose their own selection options, e.g.,
dualtree
flag of sklearn.neighbors.KDTree.queryFrom #3223, it would be nice if we could also pass distinct options values per index.
What would be a good API for that?
Describe the solution you'd like
Some ideas:
A. Allow passing a tuple
(labels, options_dict)
as indexer valueB. Expose an
options
kwarg that would accept a nested dictOption A does not look very readable. Option B is slightly better, although the nested dictionary is not great.
Any other ideas? Some sort of context manager? Some
Index
specific API?Describe alternatives you've considered
The API proposed in #3223 would look great if
method
andtolerance
were the only accepted options, but less so for arbitrary options.Additional context
No response
The text was updated successfully, but these errors were encountered: