Skip to content

numpy deprecation: Should regular_grid return a tuple? #3235

Closed

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.

Activity

  1. added 2 commits that reference this issue on Jul 1, 2018
    7319d81
    3f41d81
  2. soupault commented on Jul 1, 2018

    @soupault
    Member

    My vote is for the option 3. The question here is do we need any kind of deprecation? Probably, the most popular use case of the regular_grid output is the direct indexing with the returned grid, however, some users might be using list-specific post-processing methods (e.g. .append). Perhaps, a 1-release deprecation is a way to go...

  3. added
    🔧 type: Maintenance
    on Jul 1, 2018
  4. added this to the 0.15 milestone on Jul 1, 2018
  5. added 2 commits that reference this issue on Jul 3, 2018
    bc3bd36
    91a641d
  6. jni commented on Jul 5, 2018

    @jni
    Member

    I agree with @soupault. Option 3 is the right way to go (it is simple and fast to cast the tuple as a list for users who want that), but it needs a deprecation path. My suggestion is:

    return_type={None, tuple, list}.

    Since we're now Python 3 only, I suggest making this a keyword-only argument. =D (It'll need fixing for a backport, but the fix should happen there.)

  7. hmaarrfk commented on Jul 5, 2018

    @hmaarrfk
    MemberAuthor

    So, I do agree with the sentiment of having a deprecation cycle, but I think we should think longterm that we don't want to have kwargs that just stay there forever, for "legacy purposes".

    So in addition to deprecating the list->tuple, I think we should have a plan to deprecate the added argument.

  8. jni commented on Jul 5, 2018

    @jni
    Member

    totally happy to do that. Just add it to TODO.txt. For version 0.19. 😂

  9. JDWarner commented on Jul 14, 2018

    @JDWarner
    Contributor

    Just throwing it out there, but would simply making the change and documenting it in release notes be less disruptive to users than adding an unnecessary kwarg - so they can keep doing it wrong if they so choose - which then will disruptively break their workflow later?

    Seems like a lot of trouble including two separate deprecations, a brand-new temporary kwarg with a shelf life, and branching output paths could be avoided if we just... did the right thing.

    Put differently

    • Path direct change to Tuple: Potentially disruptive to a very small subset of users. Documented well and they handle it.
    • Option 3, with default Tuple: Immediate disruptive change to this same set of users. They are then provided the option of not changing, and some will take it - ignoring our warning that it has a sunset. Two versions later, another disruptive change for these folks (plus anyone else who decided to START using the wrong kwarg in the interim!).
    • Option 3, with default List instead of Tuple for next two versions: Everyone gets warnings all the time until they start using a kwarg which is going to go away, creating more problems.

    There should be one, correct way. My vote is just change this to Tuple directly and document it.

  10. jni commented on Jul 17, 2018

    @jni
    Member

    After discussion with @JDWarner at SciPy 2018, I'm inclined to agree with a straight switch in behaviour. Specifically, despite our existing policy, when making this decision we should consider not only the policy, but also:

    • how many people are likely to be affected by this (few or none)
    • the cost of the deprecation (in this case, four versions of fiddling, and causing people to make two adjustments over four versions, instead of a single one.

    Having said this, I suggest that we add a section Notes to the docstring that mentions the change, which version it occurred in, why, and how to fix it. That way if we have ended up breaking someone's code, they will instantly know how to fix it.

  11. added 2 commits that reference this issue on Jul 20, 2018
    3991107
    c851576
  12. added a commit that references this issue on Aug 2, 2018
    6862b32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔧 type: Maintenance

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions