Skip to content

STYLE: Enable ruff TCH on "pandas/_libs/*" #51794

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 1 commit into from
Mar 17, 2023

Conversation

v-mcoutinho
Copy link
Contributor

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

#51740, for

"pandas/_libs/*"

@v-mcoutinho v-mcoutinho changed the title Enable ruff TCH on "pandas/_libs/*" STYLE Enable ruff TCH on "pandas/_libs/*" Mar 5, 2023
@v-mcoutinho v-mcoutinho changed the title STYLE Enable ruff TCH on "pandas/_libs/*" STYLE: Enable ruff TCH on "pandas/_libs/*" Mar 5, 2023

from pandas._typing import npt
if TYPE_CHECKING:
Copy link
Member

@twoertwein twoertwein Mar 5, 2023

Choose a reason for hiding this comment

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

If ruff requires this change within a stub file, please report an issue at ruff. Using TYPE_CHECKING inside a pyi files doesn't make sense as it is only used by type checkers.

edit: at least ruff 0.0.254 doesn't seem to suggest this change

Copy link
Member

@MarcoGorelli MarcoGorelli Mar 6, 2023

Choose a reason for hiding this comment

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

good point, reported

I'm still seeing it in 0.0.254 though:

(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev$ git diff
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 484107af67..ba57fcb432 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -28,7 +28,7 @@ repos:
         types_or: [python, pyi]
         additional_dependencies: [black==23.1.0]
 -   repo: https://github.com/charliermarsh/ruff-pre-commit
-    rev: v0.0.253
+    rev: v0.0.254
     hooks:
     -   id: ruff
 -   repo: https://github.com/jendrikseipp/vulture
diff --git a/pyproject.toml b/pyproject.toml
index 58a70b584c..f2f8ed9093 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -311,7 +311,6 @@ exclude = [
 "pandas/tests/*" = ["TCH"]
 "pandas/plotting/*" = ["TCH"]
 "pandas/util/*" = ["TCH"]
-"pandas/_libs/*" = ["TCH"]
 # Keep this one enabled
 "pandas/_typing.py" = ["TCH"]
 
(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev$ pre-commit run ruff -a | grep 'index'
pandas/_libs/index.pyi:1:8: TCH002 Move third-party import `numpy` into a type-checking block
pandas/_libs/index.pyi:3:28: TCH001 Move application import `pandas._typing.npt` into a type-checking block
pandas/_libs/index.pyi:5:20: TCH001 Move application import `pandas.MultiIndex` into a type-checking block
pandas/_libs/index.pyi:6:32: TCH001 Move application import `pandas.core.arrays.ExtensionArray` into a type-checking block
pandas/_libs/window/indexers.pyi:1:8: TCH002 Move third-party import `numpy` into a type-checking block
pandas/_libs/window/indexers.pyi:3:28: TCH001 Move application import `pandas._typing.npt` into a type-checking block

Copy link
Member

Choose a reason for hiding this comment

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

looks like they've fixed it https://github.com/charliermarsh/ruff/pull/3362/files

temporarily marking this PR as 'draft' until the next ruff version comes out, hope that's OK

Copy link
Member

Choose a reason for hiding this comment

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

Or could also have something like

[tool.ruff.per-file-ignores]
"*.pyi" = ["TCH"]  # TODO: remove line when using ruff 0.0.255

in pyproject.toml

Copy link
Member

Choose a reason for hiding this comment

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

looks like there's a new ruff version

@v-mcoutinho do you want to update the ruff version please, revert the other changes, and remove pandas/_libs from pyproject.toml?

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 can't seem to find this new version, where are you seeing it exactly? ruff's github page still shows 0.0.254 as the latest version.

Copy link
Member

Choose a reason for hiding this comment

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

ah you're right, sorry, they've fixed it but haven't made a release yet, guess it'll be next week (they used to do daily releases)

Copy link
Member

Choose a reason for hiding this comment

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

They just had a new release

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 made the changes, it seems the PR closed when I tried to push but I've opened it again.

@mroeschke mroeschke added the Code Style Code style, linting, code_checks label Mar 6, 2023
@MarcoGorelli MarcoGorelli marked this pull request as draft March 6, 2023 20:47
@v-mcoutinho v-mcoutinho reopened this Mar 13, 2023
Copy link
Member

@twoertwein twoertwein left a comment

Choose a reason for hiding this comment

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

LGTM, assuming the CI is green

@MarcoGorelli MarcoGorelli marked this pull request as ready for review March 17, 2023 15:14
@MarcoGorelli MarcoGorelli added this to the 2.1 milestone Mar 17, 2023
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Nice one, thanks @v-mcoutinho (and @twoertwein of course!)

@MarcoGorelli MarcoGorelli merged commit 7b1f975 into pandas-dev:main Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants