Skip to content

MNT Switch to absolute imports enforced by ruff - #31847

Merged
jeremiedbb merged 6 commits into
scikit-learn:mainfrom
lesteve:ruff-absolute-imports
Jul 29, 2025
Merged

jeremiedbb merged 6 commits into
scikit-learn:mainfrom
lesteve:ruff-absolute-imports

Conversation

@lesteve

@lesteve lesteve commented Jul 28, 2025 •

Copy link
Copy Markdown
Member

I fixed them all with:

ruff check --fix --unsafe-fixes sklearn

Context: #31817 (comment)

Still TODO:

  • change our documented guideline
  • by default (ban-relative-imports = "parents") relative imports are allowed as long as they use a single . if I understand the doc. Maybe we want to use ban-relative-imports = "all"

@lesteve lesteve changed the title MNT Switch to absolute imports with rules enforced by ruff MNT Switch to absolute imports enforced by ruff Jul 28, 2025
@github-actions

github-actions Bot commented Jul 28, 2025 •

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 38d3e94. Link to the linter CI: here

Comment thread sklearn/neighbors/_base.py Outdated
Comment on lines 27 to 30
from sklearn.utils.validation import _to_object_array, check_is_fitted, validate_data

from ._ball_tree import BallTree
from ._kd_tree import KDTree

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

by default (ban-relative-imports = "parents") relative imports are allowed as long as they use a single . if I understand the doc. Maybe we want to use ban-relative-imports = "all"

I find it a bit weird to have a mix of relative and absolute, so I'm in favor of all absolute.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1.

@jeremiedbb jeremiedbb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Just a nitpick

Comment thread doc/developers/develop.rst Resolved

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I find such absolute imports easier to mentally resolve, both when reading and editing code.

Furthermore, I like the fact that we now have a standard tool to check that we are always consistent in our import styles (contrary to the past where we had mixed import styles creeping for years and that required manual maintenance PRs to fix them at least on two occasions).

@betatim betatim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fine for me.

I think we should not have the exception for "parent imports", use absolute imports everywhere.

The failed docs build looks like it would benefit from restarting

@betatim

betatim commented Jul 29, 2025

Copy link
Copy Markdown
Member

Scrolling through the diff and stopping at random-ish locations it doesn't seem like we are getting vastly longer lines. There are a few cases where one line imports turn into a multiline import but not very often (compared to how many lines are touched by this change)

@lesteve
lesteve force-pushed the ruff-absolute-imports branch from 512221d to 38d3e94 Compare July 29, 2025 10:08
@jeremiedbb

Copy link
Copy Markdown
Member

Alright, let's merge with 4 approvals before accumulating conflicts.

@jeremiedbb
jeremiedbb merged commit 1fe6595 into scikit-learn:main Jul 29, 2025
@lesteve
lesteve deleted the ruff-absolute-imports branch July 29, 2025 14:04
@jeremiedbb jeremiedbb mentioned this pull request Sep 3, 2025
13 tasks done
@lesteve lesteve mentioned this pull request Oct 2, 2025
74 tasks done
@beb775705-cyber

Copy link
Copy Markdown

I fixed them all with:

ruff check --fix --unsafe-fixes sklearn

Context: #31817 (comment)

Still TODO:

  • change our documented guideline
  • by default (ban-relative-imports = "parents") relative imports are allowed as long as they use a single . if I understand the doc. Maybe we want to use ban-relative-imports = "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.

6 participants