Skip to content
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

MAINT: use the define for NPY_NO_DEPRECATED_API, fix where needed #10840

Closed
wants to merge 2 commits into from

Conversation

mattip
Copy link
Contributor

@mattip mattip commented Sep 18, 2019

Build on #4351. Now that the "new" numpy API is quite mature, use it throughout the code. There was only one place I could not use the 1.7 API: in scipy/interpolate/src/_fitpackmodule.c

@mattip mattip changed the title MAINT: add a define for NPY_NO_DEPRECATED_API, fix where needed MAINT: use the define for NPY_NO_DEPRECATED_API, fix where needed Sep 18, 2019
@mattip
Copy link
Contributor Author

mattip commented Sep 18, 2019

What is the minimal version of NumPy that is supported?

@rgommers
Copy link
Member

What is the minimal version of NumPy that is supported?

1.13.3 for py35,py36, 1.14.5 for py37. defined in pyproject.toml

@rgommers rgommers added the maintenance Items related to regular maintenance tasks label Sep 18, 2019
@larsoner larsoner added this to the 1.4.0 milestone Sep 18, 2019
@mattip
Copy link
Contributor Author

mattip commented Sep 18, 2019

it seems i needed to build with setup.py build --debug to uncover more problems

@mattip
Copy link
Contributor Author

mattip commented Sep 18, 2019

.. and build with cython==0.29.13 not the unreleased head which fixes all the ndarray.ndim -> PyArray_NDIM(ndarray) problems

@rgommers
Copy link
Member

.. and build with cython==0.29.13 not the unreleased head which fixes all the ndarray.ndim -> PyArray_NDIM(ndarray) problems

If the fix is imminent in Cython for something, waiting for that and bumping the Cython version to >=0.29.14 in this PR would be fine if that's what you'd prefer.

@larsoner
Copy link
Member

bumping the Cython version to >=0.29.14 in this PR would be fine if that's what you'd prefer.

We just bumped to 0.29.13 in #10943. Might be worth looking at the discussions there to see if 0.29.14 would make sense.

@h-vetinari
Copy link
Member

Cython 0.29.14 was released a few days ago...

@ilayn
Copy link
Member

ilayn commented Nov 5, 2019

@mattip Do you mind rebasing this?

@mattip
Copy link
Contributor Author

mattip commented Nov 5, 2019

I could, but unfortunately Cython 0.29.14 did not include the fixes I was hoping for. That will apparently be part of cython 3 (search for "Properties can be defined for external extension types."). So I could change all the calls to ndarray.ndim to PyArray_NDIM(ndarray) (and related calls to other ndarray attributes), but would prefer to wait for Cython3

@larsoner
Copy link
Member

larsoner commented Nov 6, 2019

That will apparently be part of cython 3 (search for "Properties can be defined for external extension types."). So I could change all the calls to ndarray.ndim to PyArray_NDIM(ndarray) (and related calls to other ndarray attributes), but would prefer to wait for Cython3

Does anyone know when 3.0 is due? I tried a bit of searching and didn't find anything immediately. The closest was a discussion in August about remaining issues:

https://mail.python.org/pipermail/cython-devel/2019-August/005258.html

The current changelog page page at least lists the release as 3.0.0 (2019-??-??) so there is some hope for the next two months, though it's entirely possible this was just a placeholder with no meaning. I've sent an email to cython-devel asking if they have a tentative date in mind.

@tylerjereddy
Copy link
Contributor

Does anyone know when 3.0 is due?

@scoder might, but I suspect we'd be cutting it awfully close with branching in ~1 week. I see that 3.0 alpha 5 was just released.

@mattip Shall we bump this to 1.6.0 then?

@mattip
Copy link
Contributor Author

mattip commented May 20, 2020

Shall we bump this to 1.6.0 then?

Yes, seems reasonable.

@scoder
Copy link

scoder commented May 20, 2020

I would suggest to merge at least all the nice API usage changes in order to avoid even more merge conflicts in the future, and then keep using the API instead of direct struct access for code changes.

When you enable the API macro then is your choice, but yes, you might want to wait for the final release of Cython 3.0, and maybe also a bit of adoption out there (assuming that this also has a user impact for you, which I can't assess right now).

<float32_t *>outdists.data)
_vq(<float32_t *>np.PyArray_DATA(obs), <float32_t *>np.PyArray_DATA(codes),
ncodes, nfeat, nobs, <int32_t *>np.PyArray_DATA(outcodes),
<float32_t *>np.PyArray_DATA(outdists))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@scoder Cython 3.0 would make this kind of change unnecessary, so I would prefer to redo this PR once 3.0 is released.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mattip Should we bump the milestone again? I don't think we have Cython 3.x stable release yet? I believe there have been alpha/beta versions available via i.e., PyPI for quite some time now though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, let's only continue on this when cpython3.0 is fully released

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can tell Cython 3.0 has not been released, so bumping the milestone per discussion above.

@tylerjereddy tylerjereddy modified the milestones: 1.5.0, 1.6.0 May 20, 2020
@tylerjereddy tylerjereddy modified the milestones: 1.6.0, 1.7.0 Nov 13, 2020
@tylerjereddy tylerjereddy modified the milestones: 1.7.0, 1.8.0 May 13, 2021
@rgommers rgommers removed this from the 1.8.0 milestone May 13, 2021
@rgommers
Copy link
Member

@mattip this would be extremely useful to merge. Cython 3.0 is still too far off, and getting rid of like half of all our build warnings is quite valuable. What do you think about resolving conflicts here and merging in its current state?

@ilayn
Copy link
Member

ilayn commented May 13, 2021

If possible, +1 on merging and firefighting afterwards if need be. This is a long-sought-after change that we have been delaying for many major versions.

@mattip
Copy link
Contributor Author

mattip commented May 13, 2021

@scoder thoughts?

@scoder
Copy link

scoder commented May 13, 2021

thoughts?

I was hoping to get around a comment when this discussion restarted, but well… ;-)

I agree with Matti that this adds a lot of explicit C-API code that you could avoid if you started depending on Cython 3, for which a stable release, as Ralf noted, probably won't happen all too soon. It's your decision whether you want that dependency now already or not. If you want to switch to Cython 3 at some point, then following the development now and depending on exactly the next alpha release (and then future follow-up releases after you tested them) shouldn't induce too much trouble along the way. It's mostly a question of your own project constraints and needs, your distribution scheme, etc. As always, you can generate the C code, test it and ship it. You don't need to tell your users that the code was generated by an alpha version of Cython, and it won't just arbitrarily explode in your hands once it's known to work.

If that's not what you want to do, then the question is whether you can wait, or want to make the changes in this PR timely so that you can benefit from less warnings now. These changes won't break once you switch to Cython 3, they'll just add a bit of (shallow) complexity to your code now. You can try to clean that up at some later time, at once or step by step, or you can leave the code as it is then.

Both paths seem viable to me, with an (obviously entirely unbiased) preference for the first, since it seems a better investment into the future. And it would allow you to make use of, you know, all those cool new features in Cython 3. :)
But it's really your decision in the end.

@mattip
Copy link
Contributor Author

mattip commented May 14, 2021

+1 for using the latest cython 3.0 alpha release in scipy. Should I refactor the PR to do that?

@rgommers
Copy link
Member

+1 for using the latest cython 3.0 alpha release in scipy. Should I refactor the PR to do that?

While I personally don't have an issue using an alpha, it's pretty problematic to do so in a release; you cannot properly express that dependency in a way that works across install & packaging tools. So I don't think we can do this.

I'm not sure what the problem is in just merging this and opening an issue that says "when Cython 3.0 is released, revisit PR 10840 and undo the new unnecessary things there"?

@ilayn
Copy link
Member

ilayn commented May 14, 2021

Also if we do this and alpha 9 or beta 1 reveals a tiny issue with the usage then we might have to touch these anyways (small but nonzero probability) . If we are going to touch then better touch when cython 3 is out.

Meaning option 2 of @scoder seems better to me

@mattip
Copy link
Contributor Author

mattip commented May 14, 2021

I'm not sure what the problem is in just merging this ...

I stopped doing the busy-work search and replace quite early in the process. If someone else wants to take it over they are welcome.

@rgommers
Copy link
Member

I stopped doing the busy-work search and replace quite early in the process. If someone else wants to take it over they are welcome.

Ah okay, I thought this was closer to ready. I'd be interested to rebase it, and even merge the pieces that are ready. Having a clean(er) build log is really helpful when working on build system changes.

@lucascolley
Copy link
Member

lucascolley commented Jan 4, 2024

Can this be closed now that we require Cython >= 3.0.3? I can't quite tell if this PR was just about build warnings or otherwise worthwhile improvements, but I think we have squashed all Cython build warnings on main now if it's the former.

Edit: closing anyway since @mattip said

I would prefer to redo this PR once 3.0 is released.

@lucascolley lucascolley added the Cython Issues with the internal Cython code base label Jan 4, 2024
@lucascolley lucascolley closed this Jan 4, 2024
@rgommers
Copy link
Member

rgommers commented Jan 5, 2024

There are still fixes here to Cython code that are relevant, and we need to do build system updates to ensure the old NumPy API cannot be used. @mattip not sure if you have an interest in revisiting this? If not, I can do it.

@mattip
Copy link
Contributor Author

mattip commented Jan 5, 2024

I have had this on my TODO list since Cython3 came out, and would be happy to hand it off. I think closing this and opening a new PR based on some of these changes would be the right way to proceed.

@rgommers
Copy link
Member

rgommers commented Jan 5, 2024

Okay, I'll do this, thanks Matti.

rgommers added a commit to rgommers/scipy that referenced this pull request Jan 5, 2024
rgommers added a commit to rgommers/scipy that referenced this pull request Jan 8, 2024
thalassemia pushed a commit to thalassemia/scipy that referenced this pull request Jan 10, 2024
thalassemia pushed a commit to thalassemia/scipy that referenced this pull request Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cython Issues with the internal Cython code base maintenance Items related to regular maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants