Skip to content

MNT Support and test Python 3.9 #18761

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

Merged
merged 4 commits into from
Nov 10, 2020

Conversation

terencehonles
Copy link
Contributor

What does this implement/fix? Explain your changes.

Updates Python 3.8 to Python 3.9 in latest tests, and updates trove classifiers to mention Python 3.9 support. I'm not sure what else is needed to build the Python 3.9 wheels since I didn't see anything obvious in this repo that should be changed.

@terencehonles terencehonles force-pushed the support-python3.9 branch 2 times, most recently from 6dc223a to 5449fd5 Compare November 5, 2020 06:54
# NOTE(honles): scikit-image does not include pyproject.toml in its
# current release and these are what it needs to build.
# This can be removed when
# https://github.com/scikit-image/scikit-image/pull/5016
Copy link
Contributor

Choose a reason for hiding this comment

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

That MR has been merged: scikit-image/scikit-image#5016

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, but it has not been released yet. I will create a separate PR which can be merged after that is released to pypi/conda.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm also trying to get Python 3.9 wheels built too, so hopefully that will all come together in the next release

See: scikit-image/scikit-image#5052

Copy link
Member

Choose a reason for hiding this comment

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

I would rather not build scikit-image from source for now. Maybe we can only install scikit-image for the builds that are for Python PYTHON_VERSION < "3.9" for now instead.

It's an optional dependency of scikit-learn, so it should still work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So would you prefer I change this to: python -m pip install --only-binary :all: sckit-image || true? So it only installs binary packages and only if they exists? I'd have to see if anything else has to be altered, but I'd prefer not to add config that has to be updated manually and just install it automatically if it can.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @ogrisel.

@ogrisel ogrisel added this to the 0.24 milestone Nov 6, 2020
Copy link
Member

@ogrisel ogrisel 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 PR but we need to pin the version of numpy in the build dependency:

# NOTE(honles): scikit-image does not include pyproject.toml in its
# current release and these are what it needs to build.
# This can be removed when
# https://github.com/scikit-image/scikit-image/pull/5016
Copy link
Member

Choose a reason for hiding this comment

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

I would rather not build scikit-image from source for now. Maybe we can only install scikit-image for the builds that are for Python PYTHON_VERSION < "3.9" for now instead.

It's an optional dependency of scikit-learn, so it should still work.

pyproject.toml Outdated
"numpy==1.16.5; python_version=='3.7'",
"numpy==1.17.3; python_version=='3.8'",
# do not pin numpy on future versions of python to avoid incompatible numpy and python versions
"numpy; python_version>='3.9'",
Copy link
Member

Choose a reason for hiding this comment

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

We need to pin the oldest version of numpy that supports python_version == '3.9' because it will define the ABI compatibility expectations for the scikit-learn wheel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I follow this comment. This is the same as scipy, and I figured that would be acceptable. I'm not sure if you can explain your thinking a little more.

I can change it to 1.19.3 if needed, since that is the first version that has released wheels for Python 3.9. I just figured it might cut down on the maintenance burden and I assumed that was why scipy set that as their default.

Copy link
Member

Choose a reason for hiding this comment

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

We use the version of numpy pyproject.toml to build the wheels in a github actions workflow. scikit-learn has Cython extension that need numpy at build time and the generated wheel need to be built with the oldest supported version of numpy to make sure that our build do not depend on recently changes of the numpy ABI.

For instance the future scikit-learn 0.24 wheel for python 3.8 needs to be build with numpy 1.17.3 to make sure that users who have such old versions of numpy can install a binary package of scikit-learn that is binary compatible.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ogrisel yeah, I gathered as much as you explained. Not sure why scipy chose to not pin numpy the same way, but I'm fine with setting this to 1.19.3, and thanks for the pointer to the new workflow. cibuildwheels looks nice 🙂

@alfaro96 yeah I got that 😉 , but thanks for making it explicit

@ogrisel
Copy link
Member

ogrisel commented Nov 6, 2020

/cc @alfaro96 since it's related to the new wheel builder infrastructure developed in #17921.

Copy link
Member

@alfaro96 alfaro96 left a comment

Choose a reason for hiding this comment

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

Hey @terencehonles,

Thank you for your PR!

I have a few of requested changes:

  • I think that we may update the Python version used in circleci:
grep -rnw ".circleci" -e "python"
.circleci/config.yml:6:      - image: circleci/python:3.7.3-stretch
.circleci/config.yml:47:      - image: circleci/python:3.7.3-stretch
.circleci/config.yml:93:      - image: circleci/python:3.6
.circleci/config.yml:122:      - image: circleci/python:3.6
  • If we decide to update the NumPy version for Python 3.6 to 1.16.5, we should update the NUMPY_MIN_VERSION global variable in the sklearn/_min_dependencies.py file.

@@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.9'
Copy link
Member

Choose a reason for hiding this comment

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

By default, Python 3.9 is used in GitHub Actions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting I remove this? I believe it might make sense to keep this explicit since this is a C extension that may need to be pinned to a different version than what is the default. If you'd like me to remove it I can.

Copy link
Member

Choose a reason for hiding this comment

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

Let us keep then.

@@ -15,7 +15,7 @@ jobs:
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.8'
versionSpec: '3.9'
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 that the same applies for Azure Pipelines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same comment here, though I believe Azure Pipelines may not have switched the default (I know this was discussed earlier on). I also remember coming across microsoft/azure-pipelines-tasks#13708 but it looks like there has been no response there.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, same here.

# NOTE(honles): scikit-image does not include pyproject.toml in its
# current release and these are what it needs to build.
# This can be removed when
# https://github.com/scikit-image/scikit-image/pull/5016
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @ogrisel.

@terencehonles terencehonles force-pushed the support-python3.9 branch 4 times, most recently from 35e7cde to 0afb549 Compare November 7, 2020 01:58
@terencehonles
Copy link
Contributor Author

  • I think that we may update the Python version used in circleci:

I'm not sure if we can update doc-min-dependencies I bumped it to use the Python 3.9 circle CI image, and I specified Python 3.9 as the Python version. It fails during conda install, but if I'm not mistaken that job looks like it's computing the min requirements and it makes sense to be running it with the lowest Python version. Does that seem correct?

@ogrisel
Copy link
Member

ogrisel commented Nov 9, 2020

It fails during conda install, but if I'm not mistaken that job looks like it's computing the min requirements and it makes sense to be running it with the lowest Python version. Does that seem correct?

Yes Python is considered a dependency of scikit-learn as numpy, scipy, etc. So the min_dependency build of circle CI should use the oldest supported version of Python which is Python 3.6 at the moment.

@ogrisel
Copy link
Member

ogrisel commented Nov 9, 2020

Not sure why scipy chose to not pin numpy the same way, but I'm fine with setting this to 1.19.3.

If scipy pins to an older version of numpy for Python 3.9, we can do so, but we need to wait for this Python 3.9 wheel for numpy to be uploaded to that version on PyPI, otherwise we won't be able to build our own wheels.

@ogrisel
Copy link
Member

ogrisel commented Nov 9, 2020

@terencehonles To keep this PR focused and merge it quickly to prepare the scikit-learn 0.24 release, could you please revert the changes made on the circle ci configuration? They are not required to support and test Python 3.9.

We can always bump up the python versions used in circle ci in another PR but this requires more in dept testing and now is not the time to risk making the doc building infrastructure unstable ;)

Same for PyPy which is hard to test at the moment because of #18624.

@alfaro96
Copy link
Member

alfaro96 commented Nov 9, 2020

@terencehonles Do you mind updating the pyproject.toml file according to #18782 (comment)?

@terencehonles
Copy link
Contributor Author

Not sure why scipy chose to not pin numpy the same way, but I'm fine with setting this to 1.19.3.

If scipy pins to an older version of numpy for Python 3.9, we can do so, but we need to wait for this Python 3.9 wheel for numpy to be uploaded to that version on PyPI, otherwise we won't be able to build our own wheels.

@ogrisel I'm aware of that, I mean that they don't constrain future releases to the min version needed to build. It's not really important to discuss since it seems like there are more specific requirements for this package.

@terencehonles To keep this PR focused and merge it quickly to prepare the scikit-learn 0.24 release, could you please revert the changes made on the circle ci configuration? They are not required to support and test Python 3.9.

We can always bump up the python versions used in circle ci in another PR but this requires more in dept testing and now is not the time to risk making the doc building infrastructure unstable ;)

Same for PyPy which is hard to test at the moment because of #18624.

@ogrisel this PR really isn't that big and now two of you are asking for conflicting things. I changed it because @alfaro96 asked, but also because the change does need to be tested. The CI changes are not failing so I'm not sure what's your reason to not make the change now.

@terencehonles Do you mind updating the pyproject.toml file according to #18782 (comment)?

@alfaro96 done, I added some comments to explain when the constraints can be removed as Python versions are expired.

@ogrisel
Copy link
Member

ogrisel commented Nov 9, 2020

The CI changes are not failing so I'm not sure what's your reason to not make the change now.

The full doc build is very expensive and not triggered by your PR. The PyPy build is only triggered by a scheduled task it does not run on PRs.

See: https://scikit-learn.org/dev/developers/contributing.html#continuous-integration-ci

@terencehonles
Copy link
Contributor Author

The CI changes are not failing so I'm not sure what's your reason to not make the change now.

The full doc build is very expensive and not triggered by your PR. The PyPy build is only triggered by a scheduled task it does not run on PRs.

See: https://scikit-learn.org/dev/developers/contributing.html#continuous-integration-ci

It really looks like that only applies to pypy which I had thought I hadn't included, but it looks like I had left it in. Since I was going to be pushing I reverted any changes to Circle CI at your request.

Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

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

LGTM!

@ogrisel
Copy link
Member

ogrisel commented Nov 10, 2020

I just pushed a commit to check that the new pyproject.toml does not break the wheel builder workflow.

Copy link
Member

@alfaro96 alfaro96 left a comment

Choose a reason for hiding this comment

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

Thank you @terencehonles for your PR.

I would like to know if it would be possible to use oldest-supported-numpy to simplify the pyproject.toml file.

@@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.9'
Copy link
Member

Choose a reason for hiding this comment

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

Let us keep then.

@@ -15,7 +15,7 @@ jobs:
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.8'
versionSpec: '3.9'
Copy link
Member

Choose a reason for hiding this comment

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

Okay, same here.

Comment on lines +7 to +28

# PyPy needs numpy >= 1.14.0
# platform_python_implementation!='CPython' not needed >= Python 3.7 which is numpy 1.14.5
"numpy==1.13.3; python_version=='3.6' and platform_machine!='aarch64' and platform_system!='AIX' and platform_python_implementation=='CPython'",
"numpy==1.14.0; python_version=='3.6' and platform_machine!='aarch64' and platform_system!='AIX' and platform_python_implementation!='CPython'",

# AIX needs numpy >= 1.16.0
# platform_system!='AIX' not needed >= Python 3.8 which is numpy 1.17.3
"numpy==1.16.0; python_version=='3.6' and platform_machine!='aarch64' and platform_system=='AIX'",
"numpy==1.16.0; python_version=='3.7' and platform_machine!='aarch64' and platform_system=='AIX'",

# ARM needs numpy >= 1.19.0
# platform_machine!='aarch64' not needed >= Python 3.9 which is numpy 1.19.3
"numpy==1.19.0; python_version=='3.6' and platform_machine=='aarch64'",
"numpy==1.19.0; python_version=='3.7' and platform_machine=='aarch64'",
"numpy==1.19.0; python_version=='3.8' and platform_machine=='aarch64'",

# default numpy requirements
"numpy==1.14.5; python_version=='3.7' and platform_machine!='aarch64' and platform_system!='AIX'",
"numpy==1.17.3; python_version=='3.8' and platform_machine!='aarch64'",
"numpy==1.19.3; python_version=='3.9'",

Copy link
Member

Choose a reason for hiding this comment

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

What about using oldest-supported-numpy?

It would simplify the pyproject.toml file quite a lot.

WDYT @thomasjpfan and @ogrisel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems like a pretty interesting idea to me, but we'd need to upstream all the changes that were made here (existing pypy constraints and added ARM constraints)

Copy link
Member

@alfaro96 alfaro96 Nov 10, 2020

Choose a reason for hiding this comment

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

Let us accept this solution and keep us track of oldest-supported-numpy to see if we could use it in the future.

Copy link
Member

Choose a reason for hiding this comment

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

oldest-supported-numpy (implicitly by numpy developers) is not necessarily the same as oldest-supported-numpy by scikit-learn developers.

I think we are rather conservative, so the two might match, but we would have to discuss that with a dedicated issue.

Let's not block this PR further but feel free to open an issue on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you know where the pypy version constraints come from? Looking at PyPI I can see the ARM wheels so I can create a PR for that, but I don't know if I should upstream the PyPy requirement of 1.14.0

Copy link
Member

Choose a reason for hiding this comment

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

Not sure either.

Copy link
Member

Choose a reason for hiding this comment

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

See #11010 (comment). We had 7 failures with numpy==1.13.3 and none with numpy==1.14.0 for PyPy.

I do not think that we could upstream such dependencies since as @ogrisel pointed out: "oldest-supported-numpy is not necessarily the same as oldest-supported-numpy by scikit-learn developers."

Sorry for the noise!

Co-authored-by: Juan Carlos Alfaro Jiménez <JuanCarlos.Alfaro@uclm.es>
Copy link
Member

@alfaro96 alfaro96 left a comment

Choose a reason for hiding this comment

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

LGTM.

Comment on lines +7 to +28

# PyPy needs numpy >= 1.14.0
# platform_python_implementation!='CPython' not needed >= Python 3.7 which is numpy 1.14.5
"numpy==1.13.3; python_version=='3.6' and platform_machine!='aarch64' and platform_system!='AIX' and platform_python_implementation=='CPython'",
"numpy==1.14.0; python_version=='3.6' and platform_machine!='aarch64' and platform_system!='AIX' and platform_python_implementation!='CPython'",

# AIX needs numpy >= 1.16.0
# platform_system!='AIX' not needed >= Python 3.8 which is numpy 1.17.3
"numpy==1.16.0; python_version=='3.6' and platform_machine!='aarch64' and platform_system=='AIX'",
"numpy==1.16.0; python_version=='3.7' and platform_machine!='aarch64' and platform_system=='AIX'",

# ARM needs numpy >= 1.19.0
# platform_machine!='aarch64' not needed >= Python 3.9 which is numpy 1.19.3
"numpy==1.19.0; python_version=='3.6' and platform_machine=='aarch64'",
"numpy==1.19.0; python_version=='3.7' and platform_machine=='aarch64'",
"numpy==1.19.0; python_version=='3.8' and platform_machine=='aarch64'",

# default numpy requirements
"numpy==1.14.5; python_version=='3.7' and platform_machine!='aarch64' and platform_system!='AIX'",
"numpy==1.17.3; python_version=='3.8' and platform_machine!='aarch64'",
"numpy==1.19.3; python_version=='3.9'",

Copy link
Member

@alfaro96 alfaro96 Nov 10, 2020

Choose a reason for hiding this comment

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

Let us accept this solution and keep us track of oldest-supported-numpy to see if we could use it in the future.

Co-authored-by: Juan Carlos Alfaro Jiménez <JuanCarlos.Alfaro@uclm.es>
Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

LGTM, and pretty small at this point.

@terencehonles
Copy link
Contributor Author

Let us accept this solution and keep us track of oldest-supported-numpy to see if we could use it in the future.

I've opened a PR to upstream the aarch constraints scipy/oldest-supported-numpy#13, but if the PyPy change doesn't get upstreamed you can probably use the oldest-supported-numpy package when dropping Python 3.6

@terencehonles terencehonles deleted the support-python3.9 branch November 10, 2020 16:34
@ogrisel
Copy link
Member

ogrisel commented Nov 10, 2020

Thanks all!

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.

5 participants