Skip to content

BUG: Fix setitem on UNICODE, STRING, and LONGDOUBLE - #8903

Merged
juliantaylor merged 6 commits into
numpy:masterfrom
eric-wieser:fix-_setitem
Apr 11, 2017
Merged

juliantaylor merged 6 commits into
numpy:masterfrom
eric-wieser:fix-_setitem

Conversation

@eric-wieser

Copy link
Copy Markdown
Member

See #8902

This addresses some of numpy#8902, preventing precision loss
This seemed arbitrary, and was not implemented consistently.
Also make the error messages match

When combined with the last two commits, this fixes numpy#8902
if (!PyBytes_Check(op) && !PyUnicode_Check(op) &&
PySequence_Check(op) && PySequence_Size(op) > 0) {
/* Handle case of assigning from an array scalar */
if (PyArray_Check(op) && PyArray_NDIM((PyArrayObject *)op) == 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is PyArray_IsZeroDim

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as this is copied on longdouble, it might make sense to move this into a function with the setitem function as argument

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep, this exists in 3 places, all of them identical.

My worry was that wrapping this in a function would give the method authenticity - elsewhere in this file, we use a different route for converting 0d arrays to scalars.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So, here we use

PyArray_ToScalar(PyArray_BYTES((PyArrayObject *)op),
                              (PyArrayObject *)op);

But in cdouble, we have

op2 = PyArray_DESCR((PyArrayObject *)op)->f->getitem(
                                    PyArray_BYTES((PyArrayObject *)op),
                                    (PyArrayObject *)op);

Are these different in any important ways?

@juliantaylor juliantaylor Apr 10, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no clue, apparently both work. Might be worth testing using getitem in the other 3 cases and see if something fails.
As it already are two approaches in the file imo it is enough to move the copied one into a function and add a TODO

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Switched to PyArray_IsZeroDim. The way this is currently written (recursing) doesn't lend itself particularly well to being placed in a function.

And recursing is actually a pretty tidy way to deal with the refcounting here - the alternative being replacing every early return with a goto fail;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I pushed a commit moving it into a function? what does not lend itself to it?
the return is a little odd in the flow of the function but it is the same without the function.

@eric-wieser eric-wieser Apr 11, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess I was a little reluctant to pass a function pointer, but I don't have a good justification for that. Looks good to me now, anyway, so thanks

@juliantaylor
juliantaylor merged commit 19a90d0 into numpy:master Apr 11, 2017
@juliantaylor

Copy link
Copy Markdown
Contributor

thanks

@eric-wieser eric-wieser added the 09 - Backport-Candidate PRs tagged should be backported label Apr 27, 2017
@charris charris added this to the 1.12.2 release milestone May 13, 2017
@charris charris removed this from the 1.12.2 release milestone Sep 22, 2017
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Sep 22, 2017
eric-wieser added a commit to eric-wieser/numpy that referenced this pull request Sep 23, 2017
eric-wieser added a commit to eric-wieser/numpy that referenced this pull request Sep 23, 2017
theodoregoetz pushed a commit to theodoregoetz/numpy that referenced this pull request Oct 23, 2017
theodoregoetz pushed a commit to theodoregoetz/numpy that referenced this pull request Oct 23, 2017
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.

3 participants