-
-
Notifications
You must be signed in to change notification settings - Fork 12k
BUG: support axis sequence in np.trim_zeros
#29947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
34d1558 to
2a604d8
Compare
np.trim_zeros: add support for axis sequence
np.trim_zeros: add support for axis sequencenp.trim_zeros
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Sorry for taking a little while to look at this. These sorts of changes to the Python parts of NumPy are always a little inscrutable.
It's borderline but it would probably help any possibly confused users to add a release note. particularly for the axis=None change if that was intentional.
EDIT: removed an incorrect statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NM, this is OK to merge. I confused myself. Added a 2.4.0 milestone to make sure this gets merged before the next release.
|
Thanks! I'm happy to expand test coverage if you'd like that here – let me know! |
|
Go ahead if you'd like. It would make me feel a little more confident hitting the merge button without someone else looking at it. A release note about the fix/new feature would be nice too. |
2a604d8 to
93aa411
Compare
|
The last commit adds some more comprehensive tests. I added a utility to construct (input, output) pairs in order to avoid having to manually define each test case; let me know if you think this approach is too complicated. |
93aa411 to
ccadee7
Compare
ngoldbaum
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new test is complicated but easy enough to understand with the comments or by stepping through in a debugger. I'm fine with it. Just one comment about the type hints. It'd also still be really nice to get a release note for this.
| def test_multiple_axes(self, shape, axis, trim): | ||
| rng = np.random.default_rng(4321) | ||
| data, expected = self.construct_input_output(rng, shape, axis, trim) | ||
| assert_array_equal(trim_zeros(data, axis=axis, trim=trim), expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this new test takes 0.35 s to run on my M3 macbook pro. I think that's acceptable.
Done. |
|
Thanks @jakevdp! |
Fixes #29945