Skip to content

Conversation

@charris
Copy link
Member

@charris charris commented Aug 11, 2020

We no longer need to use the compatibility function after dropping support for
Python 2.7. In some cases unicode was the correct string type rather than the
bytes of the compatibility version and bugs in the array __complex__ and
array __array_interface__ methods have been fixed by changing that.

@eric-wieser
Copy link
Member

Apologies @charris, I thought I was reviewing code from @jakobjakobson13! Identicons are apparently too similar at the end of the day.

Comment on lines +152 to +149
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, if this is auto-generated then maybe we should not be editing it?

Copy link
Member Author

@charris charris Aug 12, 2020

Choose a reason for hiding this comment

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

It's in the repo, doesn't go away with git clean -xdfq and the content dates back to 2005. I think the string is intended for code generated by wrapper.c. However, in that case it is probably best to keep the message in bytes... It is a docstring for modules using wrapper.c and is directly set during module init. The tests pass with it as patched.

Copy link
Member

Choose a reason for hiding this comment

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

I think the string is intended for code generated by

I think you're right, but the top of this file also says its autogenerated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably just left over from before the tests were redone. Note that it is only used in setting up test_array_from_pyobj.py, so I think it really doesn't matter.

Copy link
Contributor

Choose a reason for hiding this comment

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

The wrapmodule.c is used in numpy/f2py/tests/test_array_from_pyobj.py and can be considered constant, that is, it can be manually modified.
For background: he file was generated with f2py as a C/API module template and later modified manually to expose various macro constants to Python for testing..

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds like that part of the header can just be removed. I'll leave this PR as is with a release note and make a separate PR with the version changes and other small cleanups suggested here.

Copy link
Member

Choose a reason for hiding this comment

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

Would you like to wait for this to be merged until the follow-on PR is made?

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand your question @mattip, the header is changed already.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mattip No :) I'm waiting for this to be merged. The follow-on PR just changes the version handling.

@charris charris force-pushed the cleanup-pystring_fromstring-usage branch from 9915e28 to 90d644c Compare August 12, 2020 00:25
@eric-wieser
Copy link
Member

eric-wieser commented Aug 12, 2020

It's tempting to split this into two phases:

  • Perform dumb text substitution of all the compat macros in one PR
  • Comb through the uses of PyBytes_... to check for things which don't make sense, and make as many PRs as needed. I can't think of many situations where bytes are the correct choice in numpy.

@charris
Copy link
Member Author

charris commented Aug 12, 2020

It's tempting to split this into two phases:

I agree that we need to replace all the compat functions, but would rather do it in smaller pieces. Look how much work this small bit is already taking :) I think blind replacement just makes it harder to find the uses that may need fixing.

@seberg
Copy link
Member

seberg commented Aug 12, 2020

Right now, I am still happy to keep it here, since its not time pressing to do the replacement and the PR is not big.

The remaining issue is mainly the f2py change, right? It sounds like most of the other actual changes were fairly clear to resolve?

I suppose for some of the things that end up being fixes, including a test might be nice (also helps with judging whether anything should have release notes), but not sure.

@pearu
Copy link
Contributor

pearu commented Aug 18, 2020

I just noticed this PR and I'd like to review the f2py bits. However, it's late here but I can review tomorrow.

@charris
Copy link
Member Author

charris commented Aug 18, 2020

@pearu Great. Other functions proposed for replacement in #17097 also appear in the f2py code so this may not be the last time review is needed.

Copy link
Contributor

@pearu pearu left a comment

Choose a reason for hiding this comment

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

LGTM from the f2py point of view.

While slightly OT, added some suggestions for updating f2py version handling.

Comment on lines +152 to +149
Copy link
Contributor

Choose a reason for hiding this comment

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

The wrapmodule.c is used in numpy/f2py/tests/test_array_from_pyobj.py and can be considered constant, that is, it can be manually modified.
For background: he file was generated with f2py as a C/API module template and later modified manually to expose various macro constants to Python for testing..

@eric-wieser
Copy link
Member

eric-wieser commented Aug 19, 2020

Think it's worth adding a test for the code snippets I give above that expose what this fixed?

At any rate, this should be BUG: or BUG,MAINT or however we combine things.

We no longer need to use the compatibility function after dropping
support for Python 2.7. In some cases unicode was the correct string
type rather than the bytes of the compatibility version and bugs in the
array `__complex__` and array `__array_interface__` methods have been
fixed by changing that.
@charris charris force-pushed the cleanup-pystring_fromstring-usage branch from 90d644c to 8c226bf Compare August 19, 2020 15:24
@charris
Copy link
Member Author

charris commented Aug 19, 2020

Think it's worth adding a test for the code snippets I give above

Been thinking about that. We could add those to the regressions checks, but in the long run it would be useful to figure out how to generate a set of comprehensive tests for both errors and descriptors. @seberg may have some ideas about the latter.

@charris charris changed the title MAINT: Remove uses of PyString_FromString. MAINT, BUG: Remove uses of PyString_FromString. Aug 19, 2020
@seberg seberg self-requested a review August 19, 2020 17:15
@charris charris force-pushed the cleanup-pystring_fromstring-usage branch from 4d4bacc to 36da1b2 Compare August 19, 2020 17:26
- Invalid conversion error bug.
- ``__array_interface__['descr']`` bug
@charris charris force-pushed the cleanup-pystring_fromstring-usage branch from 36da1b2 to 434d2f1 Compare August 19, 2020 18:49
Copy link
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

Thanks for the tests. I think with @pearu's review of the f2py stuff, this is now good to go.

@mattip
Copy link
Member

mattip commented Aug 20, 2020

I was asking generally about this PR: there are follow-on cleanups:

  • in numpy/numpy/core/src/multiarray/ctors.c where we call _array_typedescr_fromstr after converting a str to bytes then back to str
  • changes in line 205 to numpy/f2py/rules.py to use f2py_versionand delete line 53

I guess we should merge this now and then submit a follow-on PR. In it goes.

@mattip mattip merged commit eaa59b4 into numpy:master Aug 20, 2020
@mattip
Copy link
Member

mattip commented Aug 20, 2020

Thanks @charris

@charris charris deleted the cleanup-pystring_fromstring-usage branch August 20, 2020 16:56
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.

6 participants