Skip to content

MAINT: Tidy PyArray_DescrConverter - #15265

Merged
eric-wieser merged 6 commits into
numpy:masterfrom
eric-wieser:tidy-dtype-ctors
Jan 7, 2020
Merged

eric-wieser merged 6 commits into
numpy:masterfrom
eric-wieser:tidy-dtype-ctors

Conversation

@eric-wieser

@eric-wieser eric-wieser commented Jan 6, 2020 •

Copy link
Copy Markdown
Member

First part of some major cleanup to make PyArray_DescrConverter manageable.

Likely easiest to review commit-by-commit.


Follow-up will be to replace the clumsy NPY_FAIL / *at = NULL stuff internally to just use a regular return value, and write PyArray_DescrConverter as a thin wrapper.

@eric-wieser

eric-wieser commented Jan 6, 2020 •

Copy link
Copy Markdown
Member Author

Will add this to my pile of "things which didn't work today"... Splitting the first two commits to separate PRs (gh-15266, gh-15267), will revisit the this one once they're in.

Edit: Turns out all three pieces were orthogonal anyway, this PR now represents the third piece which doesn't depend on the first two.

The `goto finish` part of this if was useless, as none of the steps in `finish` were ever executed.
@eric-wieser eric-wieser changed the title MAINT/BUG: Tidy dtype ctors MAINT: Tidy PyArray_DescrConverter Jan 7, 2020
@eric-wieser
eric-wieser marked this pull request as ready for review January 7, 2020 00:54

@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.

LGTM, nice moving around much easier to read broken apart. The last if would be nice to remove, since you removed one further down? The other things I do not care about.

Comment thread numpy/core/src/multiarray/descriptor.c Outdated
Comment thread numpy/core/src/multiarray/descriptor.c Outdated
Comment thread numpy/core/src/multiarray/descriptor.c Outdated
This makes the control flow easier to reason about - notably, the only case that now falls through the `if` / `else` are `bytes` objects.
`PyBytes_Check(obj)` was always true in these if statements
The string parsing is split all over the place in PyArray_DescrConverter.
This commit brings all of it into one place, which makes `PyArray_DescrConverter` far easier to follow.

@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.

Great, thanks. I think one of the declaration fixups came in the wrong commit, but I don't mind. I will merge this as soon as the tests all pass I think, since it will create merge conflicts with the Py3K cleanup, but it has to happen one way or the other...

@eric-wieser

Copy link
Copy Markdown
Member Author

I think one of the declaration fixups came in the wrong commit,

Which one?

@seberg

seberg commented Jan 7, 2020

Copy link
Copy Markdown
Member

6d2faa6 commit, the removal of the duplicate type and len is in the next commit, but honestly I do not care, its a pretty history in either case, and only a compiler warning.

@eric-wieser

eric-wieser commented Jan 7, 2020 •

Copy link
Copy Markdown
Member Author

and only a compiler warning.

Nope, that's actually a bug in that intermediate commit. Happy to fix if you're happy to wait for CI again (or accept an empty diff between revisions as proof the rebase is safe)

@seberg

seberg commented Jan 7, 2020

Copy link
Copy Markdown
Member

OK, I don't mind waiting, but really a nitpick IMO.

We already converted the pyobject to a string on a previous line, there's no need to do it again.
@eric-wieser

eric-wieser commented Jan 7, 2020 •

Copy link
Copy Markdown
Member Author

Proof the commits are the same, and then hopefully that there's no need to wait for CI: https://github.com/numpy/numpy/compare/5da2c01a7ae3b9fc3701801ab16d234e5425436c..ac44095f8f8aca2574091bb32d6328d0b6bbf29a

@eric-wieser

Copy link
Copy Markdown
Member Author

CI passes, and this is an identical revision to the approved one, merging...

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.

2 participants