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

Drop Python 3.9 support #16637

Merged
merged 8 commits into from
Aug 27, 2024
Merged

Conversation

jameslamb
Copy link
Member

@jameslamb jameslamb commented Aug 21, 2024

Description

Contributes to rapidsai/build-planning#88

Finishes the work of dropping Python 3.9 support.

This project stopped building / testing against Python 3.9 as of rapidsai/shared-workflows#235.
This PR updates configuration and docs to reflect that.

Notes for Reviewers

How I tested this

Checked that there were no remaining uses like this:

git grep -E '3\.9'
git grep '39'
git grep 'py39'

And similar for variations on Python 3.8 (to catch things that were missed the last time this was done).

@jameslamb jameslamb added non-breaking Non-breaking change improvement Improvement / enhancement to an existing function labels Aug 21, 2024
@github-actions github-actions bot added libcudf Affects libcudf (C++/CUDA) code. Python Affects Python cuDF API. CMake CMake build issue cudf.polars Issues specific to cudf.polars labels Aug 21, 2024
@jameslamb
Copy link
Member Author

There are a bunch of new ruff errors here:

python/cudf_polars/cudf_polars/containers/dataframe.py:108:38: B905 [*] `zip()` without an explicit `strict=` parameter
python/cudf_polars/cudf_polars/containers/dataframe.py:138:50: B905 [*] `zip()` without an explicit `strict=` parameter
python/cudf_polars/cudf_polars/containers/dataframe.py:169:29: B905 [*] `zip()` without an explicit `strict=` parameter
python/cudf_polars/cudf_polars/dsl/ir.py:21:1: UP035 [*] Import from `collections.abc` instead: `Callable`
python/cudf_polars/cudf_polars/dsl/ir.py:309:32: B905 [*] `zip()` without an explicit `strict=` parameter
python/cudf_polars/cudf_polars/dsl/ir.py:429:51: B905 [*] `zip()` without an explicit `strict=` parameter
python/cudf_polars/cudf_polars/dsl/ir.py:547:12: UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)`
python/cudf_polars/cudf_polars/dsl/ir.py:551:14: UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)`
python/cudf_polars/cudf_polars/dsl/ir.py:603:24: B905 [*] `zip()` without an explicit `strict=` parameter
python/cudf_polars/cudf_polars/dsl/ir.py:605:50: B905 [*] `zip()` without an explicit `strict=` parameter
python/cudf_polars/cudf_polars/dsl/ir.py:755:33: B905 [*] `zip()` without an explicit `strict=` parameter
python/cudf_polars/cudf_polars/dsl/ir.py:764:33: B905 [*] `zip()` without an explicit `strict=` parameter
python/cudf_polars/cudf_polars/dsl/ir.py:803:52: B905 [*] `zip()` without an explicit `strict=` parameter
python/cudf_polars/cudf_polars/dsl/ir.py:912:31: B905 [*] `zip()` without an explicit `strict=` parameter
python/cudf_polars/cudf_polars/dsl/ir.py:977:52: B905 [*] `zip()` without an explicit `strict=` parameter
python/cudf_polars/cudf_polars/dsl/ir.py:1092:43: B905 [*] `zip()` without an explicit `strict=` parameter
python/cudf_polars/cudf_polars/typing/__init__.py:16:5: UP035 [*] Import from `collections.abc` instead: `Callable`
python/cudf_polars/cudf_polars/typing/__init__.py:18:5: UP035 [*] Import from `typing` instead: `TypeAlias`
python/cudf_polars/cudf_polars/typing/__init__.py:22:17: UP007 [*] Use `X | Y` for type annotations
python/cudf_polars/cudf_polars/typing/__init__.py:42:19: UP007 [*] Use `X | Y` for type annotations
python/cudf_polars/cudf_polars/utils/sorting.py:48:27: B905 [*] `zip()` without an explicit `strict=` parameter

(build link)

The zip() ones look related to these comments:

# TODO: strict=True when we drop py39
[NamedColumn(c, name) for c, name in zip(table.columns(), names)]

# TODO: strict=True when we drop py39
for c, other in zip(self.columns, like.columns)

Could use some help from someone more familiar with cudf-polars (@wence- ?).

@jameslamb jameslamb changed the title Drop Python 3.9 support WIP: Drop Python 3.9 support Aug 21, 2024
@vyasr
Copy link
Contributor

vyasr commented Aug 22, 2024

I didn't realize ruff had this rule implemented. That's nice. The comments are related, but are there because I didn't expect a linter to enforce this for us.

The strict=True parameter was added in Python 3.10, so I'm guessing that you are seeing this issue now because you bumped the requires-python in pyproject.toml and ruff uses that to determine what rules to enforce because this particular rule would be unenforceable if you supported Python<3.9. I would go ahead and add strict=True and see what, if anything, breaks. Hopefully nothing does.

@@ -115,6 +114,9 @@ ignore = [
"TD003", # Missing issue link on the line following this TODO
# tryceratops
"TRY003", # Avoid specifying long messages outside the exception class
# pyupgrade
"UP035", # Import from `collections.abc` instead: `Callable`
Copy link
Member Author

Choose a reason for hiding this comment

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

Everything else in cudf uses typing.Callable.

git grep -E 'import.*Callable'

Copy link
Contributor

Choose a reason for hiding this comment

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

Confused by this one, is this an auto-upgrade fix that ruff can do for us?

Copy link
Member 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 if this is one ruff will do automatically if asked.

But either way... it recommended this for cudf_polars but not for the rest of cudf, because cudf_polars has its own ruff config separate from the rest of cudf.

cudf_polars uses all the pyupgrade checks

"UP", # pyupgrade

All of the other Python code in the repo only has specific pyupgrade checks run over it

cudf/pyproject.toml

Lines 87 to 90 in 8d6b261

# non-pep585-annotation
"UP006",
# non-pep604-annotation
"UP007"

Happy to do whatever you want me to with this particular check, I don't have a strong preference for either pattern so I chose the one that would at least be consistent with the rest of the Python code in this repo.

Copy link
Member Author

Choose a reason for hiding this comment

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

@wence- could you please let me know what you want to do with this one, and if there's anything else I could help clarify?

Copy link
Contributor

@wence- wence- Aug 27, 2024

Choose a reason for hiding this comment

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

typing.Callable is the deprecated alias, so in cudf-polars can we migrate to using collections.abc.Callable?
I realise in cudf-classic this is more work, so we can defer doing it there. Thanks!

Copy link
Contributor

@bdice bdice Aug 27, 2024

Choose a reason for hiding this comment

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

I would propose deferring this change to a separate PR unless we can knock it out today. Completing the drop of Python 3.9 is important so we can start adding Python 3.12. We want all these platform changes done before we get too close to burndown.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok sure, happy to do that in a follow-up PR after this.

Copy link
Member Author

Choose a reason for hiding this comment

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

in a follow-up PR after this

Put up #16670 making this change across cudf.

@@ -115,6 +114,9 @@ ignore = [
"TD003", # Missing issue link on the line following this TODO
# tryceratops
"TRY003", # Avoid specifying long messages outside the exception class
# pyupgrade
"UP035", # Import from `collections.abc` instead: `Callable`
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
Copy link
Member Author

Choose a reason for hiding this comment

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

@grlee77 pointed out to me that there's actually a performance penalty associated with using | instead of a tuple in isinstance().

rapidsai/cucim#766 (comment)

from typing import Callable

from typing_extensions import TypeAlias
from typing import Callable, TypeAlias
Copy link
Member Author

Choose a reason for hiding this comment

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

TypeAlias moved to typing in Python 3.10: https://docs.python.org/3/library/typing.html#typing.TypeAlias

There are still other imports from typing_extensions in cudf-polars though, so we can't drop the dependency on it.

@jameslamb
Copy link
Member Author

I would go ahead and add strict=True and see what, if anything, breaks. Hopefully nothing does.

Alright sounds good, I've done that in recent commits. Just wasn't sure if there were places where we were knowingly relying on the non-strict behavior (i.e. zip()-ing over objects of different lengths).

I've addressed everything ruff complained about in cudf_polars. Left inline comments for some things to provide more context.

@jameslamb jameslamb changed the title WIP: Drop Python 3.9 support Drop Python 3.9 support Aug 22, 2024
@jameslamb jameslamb marked this pull request as ready for review August 22, 2024 16:58
@jameslamb jameslamb requested review from a team as code owners August 22, 2024 16:58
Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

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

Two missed py39s noted in comments -- otherwise LGTM!

python/cudf_polars/cudf_polars/containers/dataframe.py Outdated Show resolved Hide resolved
python/cudf_polars/cudf_polars/containers/dataframe.py Outdated Show resolved Hide resolved
@vyasr
Copy link
Contributor

vyasr commented Aug 22, 2024

Alright sounds good, I've done that in recent commits. Just wasn't sure if there were places where we were knowingly relying on the non-strict behavior (i.e. zip()-ing over objects of different lengths).

I seriously doubt it, and if we are I would want to find out about it!

@wence-
Copy link
Contributor

wence- commented Aug 23, 2024

question: should we upgrade ruff in pre-commit as part of these changes? I haven't tried recently if there are any additional issues. If it produces lots of warnings, let's not and we can do it separately.

Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

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

cudf-polars changes all look good, with one tiny question about the typing -> collections.abc import ignore.

@@ -115,6 +114,9 @@ ignore = [
"TD003", # Missing issue link on the line following this TODO
# tryceratops
"TRY003", # Avoid specifying long messages outside the exception class
# pyupgrade
"UP035", # Import from `collections.abc` instead: `Callable`
Copy link
Contributor

Choose a reason for hiding this comment

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

Confused by this one, is this an auto-upgrade fix that ruff can do for us?

python/cudf_polars/pyproject.toml Show resolved Hide resolved
@jameslamb
Copy link
Member Author

question: should we upgrade ruff in pre-commit as part of these changes? I haven't tried recently if there are any additional issues. If it produces lots of warnings, let's not and we can do it separately.

I just tried updating it to the latest version (0.6.2). 41 new non-auto-fixable errors were raised, mainly the those about using == to compare dtypes, similar to rapidsai/cucim#767.

I think we should not try to upgrade ruff as part of this PR.

@jameslamb
Copy link
Member Author

/merge

@rapids-bot rapids-bot bot merged commit efa9770 into rapidsai:branch-24.10 Aug 27, 2024
87 checks passed
@jameslamb jameslamb deleted the drop-python-3.9 branch August 27, 2024 16:02
rapids-bot bot pushed a commit that referenced this pull request Aug 28, 2024
Follow-up to #16637.

Once this project's minimum support Python version was bumped up to Python 3.10, `ruff` started raising this error from `pyupgrade`:

```text
Import from `collections.abc` instead: `Callable`
```

* ruff docs: https://docs.astral.sh/ruff/rules/deprecated-import/
* `typing` docs saying that `typing.Callable` is deprecated starting in Python 3.9 https://docs.python.org/3/library/typing.html#typing.Callable
* context: #16637 (comment)

This proposes accepting that suggestion, so that `cudf` won't be broken whenever `Callable` is removed from the `typing` module.

Authors:
  - James Lamb (https://github.com/jameslamb)

Approvers:
  - Lawrence Mitchell (https://github.com/wence-)
  - Kyle Edwards (https://github.com/KyleFromNVIDIA)

URL: #16670
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CMake CMake build issue cudf.polars Issues specific to cudf.polars improvement Improvement / enhancement to an existing function libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants