Repository navigation
DEP: deprecate rollaxis - #9475
Conversation
| if row_axis > col_axis: | ||
| row_axis -= 1 | ||
| y = rollaxis(rollaxis(x, col_axis, x.ndim), row_axis, -1) | ||
| y = moveaxis(moveaxis(x, col_axis, -1), row_axis, -2) |
There was a problem hiding this comment.
This can be done with a single call to moveaxis
|
I'm +1 for moving internal uses of rollaxis to moveaxis. I'm -1 on actually deprecating rollaxis. A louder warning in the docstring for rollaxis against using it would be great (e.g., "We recommend using moveaxis instead."). Take a look at the docs for We don't actually remove functionality in NumPy unless absolutely necessary, and we don't deprecate anything unless we actually plan to remove it. |
|
Don't forget the DEP: and MAINT: commit prefices. Also, this fails because you're not hiding deprecation warnings in rollaxis tests |
|
@shoyer: to be clear, by warning you mean documentation-only, as opposed to an actual python warning. |
|
Perhaps we should introduce a |
|
I'm with @shoyer on this one. |
Sure, but only if we can silence the warning by default. Otherwise it's an even more annoying version of DeprecationWarning -- one that's entirely useless! A red box like what you find in the Python docs for deprecated functions could be a nice approach: (Notice that none of these functions actually issue a warning when you use them.) |
|
Thanks for the comments, I've addressed the issues mentioned so far. As for the deprecation, I would say there must be some sort of it. This little text found in Should we tackle this now or on another PR? |
Maybe another PR? There's a long list of semi-deprecated functions. Clarifying that could require some discussion. |
|
I've added #9478 so we don't lose track of this. |
|
|
||
| This function continues to be supported for backward compatibility, but you | ||
| should prefer np.moveaxis. The np.moveaxis function was added in NumPy | ||
| 1.11. |
There was a problem hiding this comment.
referring to this as `moveaxis` will cause a link to be generated
There was a problem hiding this comment.
Is it because of the missing tick or the additional np.?
There was a problem hiding this comment.
Both, I think. There's nothing special about "np" - remember, the module's called "numpy" (but that's implied anyway in references)
| if row_axis > col_axis: | ||
| row_axis -= 1 | ||
| y = rollaxis(rollaxis(x, col_axis, x.ndim), row_axis, -1) | ||
| y = moveaxis(x, [row_axis, col_axis], [-2, -1]) |
There was a problem hiding this comment.
Might be inclined to pass tuples here, if only because the function used internally is called normalize_index_tuple
There was a problem hiding this comment.
Also, the tests are failing here. travis says
ValueError: repeated axis in
sourceargument
so I'm guessing this occurs when row_axis and col_axis are equal. Perhaps we do need two moveaxis here.
There was a problem hiding this comment.
I'm a bit lost as to why if row_axis > col_axis: row_axis -= 1 is done.
There was a problem hiding this comment.
Looks like a crutch for the rollaxis behaviour to me
There was a problem hiding this comment.
The commit that introduced this function is 4 years old, a292614, and the code hasn't been touched since.
There was a problem hiding this comment.
And in fact, after removing it, there's an assertion for nonequality at the caller
There was a problem hiding this comment.
So to conclude: just remove those two lines
There was a problem hiding this comment.
Ah yes, I get it now: If if row_axis > col_axis, and col_axis is moved to the end of the shape first, one needs to row_axis -= 1 to still get the right axis when moving the second one to the end.
Indeed, we don't need this anymore. Praised be moveaxis!
eric-wieser
left a comment
There was a problem hiding this comment.
LGTM, but needs squashing - we can do that from GitHub's ui if needed
|
@nschloe Could you add a comment to |
|
@charris Under deprecations? |
|
Oh, sorry. I see that no actual warning is issued, so no note is needed. |
|
Late here, but hurray for this cleanup! (and for changing the main documentation to make it clearer that |
|
@eric-wieser Want to finish this up? |
|
Thanksfor the patch @nschloe! |
|
Interestingly this seems to cause a significant performance decrease. I don't think we should reverse this, but maybe |
The changelog of 1.11 says about the then-new moveaxis:
I've recently stumbled upon rollaxis's weirdness myself, so perhaps it's time to deprecate it.
This PR replaces all occurrences of
rollaxisby its correspondingmoveaxisequivalent, and arguably the code becomes clearer. For example, instead ofthe new
makes clear that
iaxismoved to the first spot, then something happens, and then it's moved back.