Skip to content

ENH,DEP: Allow multiple axes in expand_dims - #14051

Merged
seberg merged 6 commits into
numpy:masterfrom
larrybradley:expand-dims-axis
Dec 2, 2019
Merged

seberg merged 6 commits into
numpy:masterfrom
larrybradley:expand-dims-axis

Conversation

@larrybradley

Copy link
Copy Markdown
Contributor

This PR allows the axis keyword in expand_dims to be a tuple of ints. Previously, axis could only be an int.

This issue was previously discussed in #12290 and the changes are based on #12290 (comment).

This PR also removes the deprecation added in v1.13 (2017-05-17), where previously axis could be outside of the range (-a.ndim - 1) <= axis <= a.ndim. Such an axis value will now raise an AxisError. Please let me know if it's too soon to remove this deprecation (I could not find any dev docs stating the length of the numpy deprecation cycle).

Closes #12290.

Comment thread numpy/lib/tests/test_shape_base.py Resolved
Comment thread numpy/lib/tests/test_shape_base.py Resolved

@eric-wieser eric-wieser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, pending comments from ages ago

Comment thread numpy/lib/shape_base.py Resolved
Comment thread numpy/lib/shape_base.py Resolved
Comment thread numpy/lib/shape_base.py Resolved

@eric-wieser eric-wieser left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs two release notes:

  • 14051.new_feature.txt, stating that a tuple of axes can be passed
  • 14051.expired.txt, stating that the deprecation of out-of-range axes from 1.13.0 has expired.

Have a look at the other files in that directory for examples of how to write these.

@eric-wieser eric-wieser changed the title ENH: Allow multiple axes in expand_dims ENH,DEP: Allow multiple axes in expand_dims Sep 13, 2019
@larrybradley

Copy link
Copy Markdown
Contributor Author

@eric-wieser I've added the release notes.

@larrybradley

Copy link
Copy Markdown
Contributor Author

@eric-wieser Can this be merged now? Is there anything else I need to do?

@eric-wieser eric-wieser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release notes have a typo, otherwise looks good.

Milestoning for 1.18.0 simply because the PR text contains 1.18.0, and it would be a shame to have to rebase

@eric-wieser eric-wieser added this to the 1.18.0 release milestone Nov 29, 2019
@eric-wieser

Copy link
Copy Markdown
Member

@larrybradley, I don't have permission to commit the changes above myself through the web gui as you haven't ticked "allow maintainers to make changes"

@eric-wieser

Copy link
Copy Markdown
Member

@charris, shall we merge as is and fixup the release note later?

@larrybradley

Copy link
Copy Markdown
Contributor Author

@eric-wieser I actually do have the option selected to allow edits from maintainers. I'm not sure why you couldn't commit. I accepted all your suggestions. Thanks!

@eric-wieser eric-wieser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, thanks. @seberg, any final comments?

I suppose in principle this could hit the mailing list, but this seems like such a natural extension it seems necessary.

@seberg seberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me, one more small behaviour thing and doc nitpick. Negative axis are a bit more confusing with multiple insertions :). Since the old was also the axis in the expanded array, it does seem very straight forward. I am happy with putting it in right away 1.18, but out of principle, lets just ping the list.

Comment thread numpy/lib/shape_base.py Resolved
Comment thread numpy/lib/shape_base.py
# and uncomment the following line.
# axis = normalize_axis_index(axis, a.ndim + 1)
return a.reshape(shape[:axis] + (1,) + shape[axis:])
if type(axis) not in (tuple, list):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, even only tuple would probably be OK.

Comment thread numpy/lib/tests/test_shape_base.py Resolved
Comment thread numpy/lib/shape_base.py Resolved
@seberg

seberg commented Dec 2, 2019

Copy link
Copy Markdown
Member

Thanks Larry and Eric, lets put this in. I do not expect any more replies on the mailing list, except maybe one or two cheers ;).

@seberg
seberg merged commit 03d4897 into numpy:master Dec 2, 2019
@larrybradley
larrybradley deleted the expand-dims-axis branch December 3, 2019 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: expand_dims by multiple dimensions

4 participants