On Sun, Jul 19, 2020 at 10:27 PM Jonathan Goble <jcgoble3@gmail.com> wrote:
One use case that comes up in xarray and pandas is support for indicating indexing "modes". For example, when indexing with floating point numbers it's convenient to be able to opt-in to approximate indexing, e.g., something like:
array.loc[longitude, latitude, method='nearest', tolerance=0.001]

I had to stare at this for a good 30 seconds before I realized that this wasn't a function/method call. Except for the square brackets instead of parentheses, it would be.
Honestly, this whole idea smells to me like just wanting another type of function call with different semantics.
IMHO the above example would be better spelled as:
array.loc.get(longitude, latitude, method='nearest', tolerance=0.001)

The problem is that with Pandas, Xarray, and other data frame/data array libraries, using slices is typical.  Continuing with the example:

arr.loc[45:46, 69:70, altitude=300:400, tolerance=0.0001, projection="WGS1984"]

There's no reason to tack a function onto the .loc accessor, it could just be a method on the array/data frame itself.  So there are no extra characters.  But doing this with parentheses would need a different new feature of allowing slices directly as arguments.

That said, pandas.IndexSlice and numpy.s_ both provide accessors to allow passing slices more easily.  So this is possible now:

arr.get(I[45:46], I[69:70], altitude=I[300:400], tolerance=0.0001, projection="WGS1984")

... I mean, assuming someone writes an appropriate .get() method for their favorite data array/frame library.  But Python itself has everything needed.