-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
ENH: Add ndmax param for numpy.array #16667
Conversation
369cd27
to
c4e1f02
Compare
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 for the patch. I'm not yet sure whether a ndmax
argument to array
is the right solution, but this patch does a nice job of showing it's a straighforward one.
At some point I'll read through the original issue and come back to this.
PyArray_FromAny_MaxDim(PyObject *op, PyArray_Descr *newtype, int maxdims, | ||
int min_depth, int max_depth, int flags, PyObject *context) |
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.
What's the difference between maxdims
and max_depth
?
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.
max_depth
is like a guard, if the discovered depth is more than that, the creation fails
The ndmax param specifies the maximum depth at which the multiarray is created from the source object.
Thanks for the PR. Sorry for being late to the party, but I realize there is not actually much overlap with my PR, so its fine. We have to figure out what the exact API is that we want, e.g. I could imagine just fixing One thing that probably currently fails is if the input is already an array(-like), i.e. we should probably pass in |
One API consideration. If we add this argument (whatever it is) we should deprecate ragged arrays for objects as well probably (although that can be a followup of course). That may be argument for a "maximum" as opposed to a fixed number of dims though. |
@seberg Indeed it currently fails if the input is an array-like. What "ragged arrays for objects" do you mean? |
See NEP 34 |
Very outdated, and mostly covered by NEP 34. We may want to continue this as an idea for consideration at some point, but would need to expose the discovery function. |
This PR implements the proposal in #5933.
The parameter makes it possible to prevent
array
from digging deeper into the input, even if the lengths at the the next level are all equal.Example: