-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
MAINT/TST: Tidy dtype indexing #9947
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
…tions Benefits of new structure: * Checking of fields doesn't happen twice * No longer any fear of possible recursion * Makes it easy to add sq_item later Also tidies initialization of the PySequenceMethods struct
09c4dd5
to
9271d81
Compare
static PyObject * | ||
_subscript_by_index(PyArray_Descr *self, Py_ssize_t i) | ||
{ | ||
PyObject *name = PySequence_GetItem(self->names, i); |
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.
Using PySequence_GetItem
here means we don't have to implement our own handling of negative indices
int value = PyArray_PyIntAsInt(op); | ||
int orig_value = value; | ||
|
||
Py_ssize_t i = PyArray_PyIntAsIntp(op); |
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.
Changed to Py_ssize_t
to avoid compiler warnings.
return NULL; | ||
} | ||
name = PyTuple_GET_ITEM(self->names, value); | ||
retval = descr_subscript(self, name); |
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 recursion was a strange way to handle this, and caused the field check to occur twice.
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.
Looks good, code quite a bit clearer now (though I'm surprised we need the special unicode/bytes handling - one would hope there is some standard way of doing this; anyway, beyond this PR...)
Really that's just because we're too lazy to call EDIT: Actually, this is not about laziness - the problem is that if you hit an exception while trying to build an exception message in the C code, you end up with no stack trace, and have no idea what actually went wrong. |
Don't worry about it - or at least not just for this piece - it would seem something that could be cleaned up more generally. This one looks all OK and tests passed, so I'll merge. |
Previously
descr_subscript
would recurse, which was needlessly confusing.Extracted from #8814, which fell into the trap of combining ENH with MAINT.