-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Change to non-deprecated NumPy C API #2498
Comments
Thanks for bringing this up and collecting the sources. |
Good point. Probably best to respect NumPy's deprecation mechanism, not exposing array attributes only if
|
I spent some time editing the numpy.pxd file to avoid these warnings, found the main blocker was PyArray_BASE because it is commented out with a note that it has the wrong refcount semantics. If that could be fixed (possibly also PyArray_DESCR, ill have to double check), then I think the pxd file can be made recent-numpy-friendly. The refcount semantics are above my pay grade though, no idea how to make that viable. |
No idea about the refcount thing – I'd check In general unfortunately the the API deprecations weren't really thought through as part of a comprehensive plan, so there may well be some idiosyncrasies. I'm not really sure where we're going with them either, or how much benefit they provide. For |
Doesn't ring a bell here. A date from |
I think they are stalled out. We should probably make a decision if we are going to make further attempts to hide the internals, or just give up on the whole thing. Backwards compatibility is a real problem here, and I don't think f2py is completely compliant, it does some content swapping on ndarrays for which we have no interface. The functions are nice for reasons other than hiding, type checking, for instance, but they are far from complete. |
The only thing I can think of regarding the base is that there were several changes to the chain of references to work around chain length limitations. Or so ISTR. |
Now that I have a real keyboard: The place saying there is an issue with refcount semantics: https://github.com/cython/cython/blob/master/Cython/Includes/numpy/__init__.pxd#L399 The place that currently accesses If |
I don't see either of Numpy itself does a lot of direct access to the structure, because the functions cannot be used as lvalues. Basically, we provide no way to set the structure values outside of NumPy. Maybe that needs to be looked at. |
I wonder why cython provides that interface, since inside NumPy they either share the data pointer or should be using writeback semantics. The implementation of {g,s}et_array_base follows neither of those conventions. I hope there is no code in the wild that uses these functions. |
If you need to mutate the array base in place (and I'm not sure that anyone does), then you're supposed to use |
@scoder: any idea which parts of the numpy pxd file are load-bearing? @ numpy people: If the 1.7 deprecation is no longer popular, can a lot of this be solved by just disabling the warning? |
This is probably not the best place to discuss that, but: generally we do prefer that people use the new over the old API right? Doesn't mean we have to ever turn the deprecation into an error. Aside from this Cython issue I haven't heard many complaints. |
I'll be happy to move the conversation elsewhere, have a place in mind? Definitely don't want to hijack the thread.
This is probably right, but Google tells me there are many people who are confused by these warnings. In pandas we want to silence them largely because they flood the build log and make it easy to miss unrelated warnings. Seems like the best case is for this to be updated in cython-land. Until that becomes a reality, please consider a mechanism to let downstream authors silence these warnings. |
(sorry for the slow reply)
The numpy-discussion mailing list is probably best.
The next opportunity for that is NumPy 1.16.0, which is a ways away. If we cannot solve the remaining Cython issue before the 1.16 release, then adding a new environment variable that silences the warning would not be unreasonable. I'll open a NumPy issue for that now (EDIT: done in numpy/numpy#11653) |
@jbrockmendel the change to {sg}et_array_base has been merged. Could you try again to update the API version for cython? |
I'm not clear on what you're asking for here. Do you mean see if the NPY_NO_DEPRECATED_API warnings can be gotten rid of? |
You commented above
Could you try that again on latest head? |
OK, I've made some progress. I'll make a dummy PR to show the relevant edits and describe what still breaks. |
I put some work into this. I did not make it into a PR yet, the work is on a branch in my fork because I am really unsure about this. I made both pandas and scipy work with this branch of cython. Here are way too many of my random thoughts about the process, with some questions at the end. Cython
|
Cython itself should avoid all use of the deprecated API, so thanks for #2559. I am also in favor of a mapping of attributes to function calls, there is precedence for it with Python's |
Note that almost all the internal uses of this function in numpy were removed as a fix for numpy/numpy#11265 |
Once gh-3115 goes in, we can move tests from the |
Is this done now, or is there still anything missing? Cython doesn't currently set the NumPy deprecated API marker itself, so that's left to users. Is that ok, or can/should we do anything else to help them? |
I think we can close this. Things like this PR in scipy can be finished once cython releases 3.0. |
So is the warning text still expected with the latest cython releases? |
@matanox yes it is, but you can now explicitly ask NumPy to not expose deprecated API since Cython itself doesn't use it anymore. Like so: |
Thanks a lot for all the work on cython and this issue. With cython 3.0.8 I got the original warning, and by adding As I gather from gleaning the comment trail, this is left for users to specify as I have, due to some reasons of correctness which I couldn't completely gather myself. Should we expect to have to change from 1.9 in there to something else in the short term? |
No, you should be all set, it shouldn't reappear.
NumPy is warning here that those APIs are deprecated. It cannot just not expose them, since that would break users that actually do need the deprecated APIs (like Cython used to). |
Thanks!!! I was half-guessing something along those lines. I guess in highly deprecation-lagging code projects, leaving this suppression optional enables one to write/maintain code using deprecated numpy api going backwards than 1.9 while using cython for compilation. Since the warning comes from numpy (pre-compilation?) code then this warning supression is practically global to the compilation process and cython does not want to globally block deprecated numpy api for those who do use deprecated numpy api in their code. Probably because numpy either exposes and allows deprecated api use with a warning, or blocks the use of deprecated api, and hence blocking old api breaks user code that expects it. |
Random question (and happy to raise this in a new issue if needed) Thought NumPy's Cython API moved upstream, but just saw this file cython/Cython/Includes/numpy/math.pxd Line 20 in f3cad15
Should this file be dropped? Was it already added upstream in NumPy somewhere? |
See gh-5967 for that. |
Oops thanks Ralf! 🙏 GH search failed me 😞 |
This is an issue to summarize the current status of NumPy C API support and what can/should be done to update Cython. (cc @mattip, this is what I was talking about yesterday - could be a useful thing to work on).
Currently Cython uses a NumPy API that has been deprecated since NumPy 1.6.0 in 2013.
The Cython docs say here: "For the time being, it is just a warning that you can ignore.".
It is about time to update this, it will save users a lot of confusion and shorten the build logs of many projects by hundreds of lines.
@nouiz wrote a summary of how to support both old (<1.6.0) and new API:
I would suggest that it's either no longer needed to support the old <1.6 API, or make that opt-in rather than the default (to avoid all the build warnings while remaining compatible with very old NumPy versions). Would be good to get the opinion of the Cython team on this before starting work on this.
Here is an example of changing to the new API and avoiding the build warnings for
scipy.optimize
: https://github.com/scipy/scipy/pull/4351/files. Linking because the use ofnumpy_nodepr_api
there (the defines and passing them todistutils
) may be useful to other projects; it's a bit nontrivial to get right.The text was updated successfully, but these errors were encountered: