Reading about PEP472, which would have allowed indexing with keyword arguments like
da[x=10]
made me wonder: why don't we use __call__ to get the same effect but just with curved brackets instead of square ones? i.e.
da(x=10)
We don't currently use __call__ on DataArray or Dataset for anything else.
I presume there is some good reason why this design decision was taken, but I'm just wondering what it is.
(Also has the ship permanently sailed on PEP472 now?)
Thanks for the suggestion @TomNicholas
I鈥檇 be -0.5 on this; it鈥檚 unpythonic given it鈥檚 not a call, and I do think it鈥檚 generally worth being consistent with the wider language.
There may also be functions that check whether arguments are callable (where / assign) that would break.
I also think our current solution of .sel is pretty good. If there鈥檚 demand for .loc(x=2), that would less intrusive than on the main object.
Agreed with @max-sixty.
I also like sel and isel as they are clearly distinguishable.
It is not clear to me if parenthesis corresponds to sel or isel.
For me, the largest drawback of sel and isel is the fact that autocompleters can not suggest the dimension names (it is another issue though)
I'm pretty happy with the .sel() API. One major advantage over using __call__ is that you can Google search for something like "xarray sel" and get sensible results.
The main downside is that you can't use it for assignment, but that wouldn't be solved by overriding __call__ either.
There may also be functions that check whether arguments are callable (where / assign) that would break.
I didn't think of this one.
These are all good reasons - I was just kind of idly wondering :man_shrugging:
Will close now.
Most helpful comment
Thanks for the suggestion @TomNicholas
I鈥檇 be -0.5 on this; it鈥檚 unpythonic given it鈥檚 not a call, and I do think it鈥檚 generally worth being consistent with the wider language.
There may also be functions that check whether arguments are callable (
where/assign) that would break.I also think our current solution of
.selis pretty good. If there鈥檚 demand for.loc(x=2), that would less intrusive than on the main object.