Skip to content

numpy deprecation: Should regular_grid return a tuple? #3235

@hmaarrfk

Description

@hmaarrfk

Returns
-------
slices : list of slice objects
A slice along each dimension of `ar_shape`, such that the intersection
of all the slices give the coordinates of regularly spaced points.

Numpy decided to deprecacte multi-indexing with anything other than a tuple.

regular grid currently returns a list. It might be useful to keep up with numpy's API, and as such, we should return a tuple.

For example, just below in _regular_grid.py

grid = regular_grid(ar_shape, n_points)
seed_img = np.zeros(ar_shape, dtype=dtype)
seed_img[grid] = 1 + np.reshape(np.arange(seed_img[grid].size),
seed_img[grid].shape)

uses the output directly to index a numpy array.

Unfortunately, lists are not tuples, and this would cause a breaking change in the (internal) API.

How should we proceed with this?

Ideas I have:

  1. Check the numpy version, if greater than 1.15 then we can return a tuple.
  2. Return a list until numpy decides to change their implementation
  3. Return a tuple instead of a list.

I kinda like 3, but doesn't seem prudent.

Edit: it seems that this is actually an external facing API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions