Sorry if this isn't the right thread -- there's a few now.

But for an example of using both positional and keyword index parameters:

I maintain a library (gridded) that provides an abstraction over data on various types of grid (in this case generally Oceanographic model output) -- they can be rectangular grids, curvilinear, unstructured triangular, ....  The point of the library is to save the user from having to understand how all those grids work  and, rather, be able to work with the data as if it were a continuous field. For example, if I want to know the sea surface temperature at a given location, I need to figure out what cell that location is in, what the values are at the corners of that cell, and then interpolate over the cell.

After abstracting that, one can create a gridded.Variable object, and then do:, 28.432)

and get the value at those coordinates.

So it would be pretty nifty to do:

sea_surface_temp[-78.123, 28.432], which of course I could do with Python as it is.

But in some instance, there is more than one way to interpolate, so it would be great to have:

sea_surface_temp[-78.123, 28.432, interp='linear']

and that would require having mixed positional and keyword index parameters.


On Sun, Sep 27, 2020 at 6:48 PM Stephan Hoyer <> wrote:
On Sat, Sep 26, 2020 at 8:40 PM Steven D'Aprano <> wrote:
On Sat, Sep 26, 2020 at 01:47:56PM -0300, Sebastian Kreft wrote:

> In this fashion have you considering having keyword only indices, that is
> to only allow either obj[1, 2] or obj[row=1, col=2] (if the class supports
> it), and disallow mixing positional and keyword indices, meaning obj[1,
> col=2] would be a SyntaxError.

That would severely reduce the usefulness of this feature for me,
probably by 80 or 90%, and possibly make it useless for xarray and

(I don't speak for the pandas or xarray devs, I'm happy to be

From my perspective as a developer for both xarray and pandas, both "mixed" and "keyword only" indexing have use cases, but I would guess keyword only indexing is more important.

In xarray, we currently have methods that awkwardly approximate keyword only indexing (e.g., xarray.DataArray.sel() and xarray.DataArray.isel() both allow for named dimensions with **kwargs), but nothing for the "mixed" case (neither method supports positional *args).
Python-ideas mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct:

Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython