Skip to content

Use absolute imports in Cython code #32315

Closed

Description

@lesteve

This is a follow-up of #31847 where we switched to absolute imports for Python files thanks to ruff but not Cython files. Maybe one day this can be enforced by cython-lint --ban-relative-imports, see MarcoGorelli/cython-lint#149

Tip

If you want to work on this, please:

  • do one Pull Request per file
  • add a comment in this issue saying which link you want to tackle so that different people can work on this issue in parallel
  • write Part of #32315 in your Pull Request description so that progress on this issue can more easily be tracked

As an example PR you can look at #32316.

Here is the list of Cython files to tackle

  • sklearn/cluster/_dbscan_inner.pyx MNT Switch to absolute imports in sklearn/cluster/_dbscan_inner.pyx #32316
  • sklearn/cluster/_hdbscan/_linkage.pyx
  • sklearn/cluster/_hdbscan/_reachability.pyx
  • sklearn/cluster/_hdbscan/_tree.pxd
  • sklearn/cluster/_hierarchical_fast.pxd
  • sklearn/cluster/_hierarchical_fast.pyx
  • sklearn/cluster/_k_means_common.pyx
  • sklearn/cluster/_k_means_elkan.pyx
  • sklearn/cluster/_k_means_lloyd.pyx
  • sklearn/decomposition/_online_lda_fast.pyx
  • sklearn/ensemble/_gradient_boosting.pyx @Ganasekhar-gif
  • sklearn/ensemble/_hist_gradient_boosting/_binning.pyx
  • sklearn/ensemble/_hist_gradient_boosting/_bitset.pxd
  • sklearn/ensemble/_hist_gradient_boosting/_bitset.pyx
  • sklearn/ensemble/_hist_gradient_boosting/common.pxd
  • sklearn/ensemble/_hist_gradient_boosting/_gradient_boosting.pyx
  • sklearn/ensemble/_hist_gradient_boosting/histogram.pyx
  • sklearn/ensemble/_hist_gradient_boosting/_predictor.pyx
  • sklearn/ensemble/_hist_gradient_boosting/splitting.pyx
  • sklearn/feature_extraction/_hashing_fast.pyx
  • sklearn/linear_model/_cd_fast.pyx
  • sklearn/linear_model/_sag_fast.pyx.tp
  • sklearn/linear_model/_sgd_fast.pyx.tp
  • sklearn/manifold/_barnes_hut_tsne.pyx
  • sklearn/manifold/_utils.pyx
  • sklearn/metrics/cluster/_expected_mutual_info_fast.pyx
  • sklearn/metrics/_dist_metrics.pxd.tp
  • sklearn/metrics/_dist_metrics.pyx.tp
  • sklearn/metrics/_pairwise_distances_reduction/_argkmin_classmode.pyx.tp
  • sklearn/metrics/_pairwise_distances_reduction/_argkmin.pxd.tp
  • sklearn/metrics/_pairwise_distances_reduction/_argkmin.pyx.tp
  • sklearn/metrics/_pairwise_distances_reduction/_base.pxd.tp
  • sklearn/metrics/_pairwise_distances_reduction/_base.pyx.tp
  • sklearn/metrics/_pairwise_distances_reduction/_datasets_pair.pxd.tp
  • sklearn/metrics/_pairwise_distances_reduction/_datasets_pair.pyx.tp
  • sklearn/metrics/_pairwise_distances_reduction/_middle_term_computer.pxd.tp
  • sklearn/metrics/_pairwise_distances_reduction/_middle_term_computer.pyx.tp
  • sklearn/metrics/_pairwise_distances_reduction/_radius_neighbors_classmode.pyx.tp
  • sklearn/metrics/_pairwise_distances_reduction/_radius_neighbors.pxd.tp
  • sklearn/metrics/_pairwise_distances_reduction/_radius_neighbors.pyx.tp
  • sklearn/metrics/_pairwise_fast.pyx
  • sklearn/neighbors/_binary_tree.pxi.tp
  • sklearn/neighbors/_partition_nodes.pxd
  • sklearn/neighbors/_quad_tree.pxd
  • sklearn/neighbors/_quad_tree.pyx
  • sklearn/preprocessing/_csr_polynomial_expansion.pyx
  • sklearn/preprocessing/_target_encoder_fast.pyx
  • sklearn/svm/_liblinear.pyx
  • sklearn/svm/_libsvm.pyx
  • sklearn/svm/_libsvm_sparse.pyx
  • sklearn/tree/_criterion.pxd
  • sklearn/tree/_criterion.pyx
  • sklearn/tree/_partitioner.pxd
  • sklearn/tree/_splitter.pxd
  • sklearn/tree/_splitter.pyx
  • sklearn/tree/_tree.pxd
  • sklearn/tree/_tree.pyx
  • sklearn/tree/_utils.pxd
  • sklearn/tree/_utils.pyx
  • sklearn/utils/arrayfuncs.pyx
  • sklearn/utils/_fast_dict.pxd
  • sklearn/utils/_fast_dict.pyx MNT Switch to absolute imports in sklearn/utils/_fast_dict.pyx #32317
  • sklearn/utils/_heap.pxd
  • sklearn/utils/_heap.pyx
  • sklearn/utils/murmurhash.pxd
  • sklearn/utils/murmurhash.pyx
  • sklearn/utils/_random.pxd
  • sklearn/utils/_random.pyx
  • sklearn/utils/_seq_dataset.pxd.tp
  • sklearn/utils/_seq_dataset.pyx.tp
  • sklearn/utils/_sorting.pxd
  • sklearn/utils/sparsefuncs_fast.pyx
  • sklearn/utils/_vector_sentinel.pxd
  • sklearn/utils/_weight_vector.pyx.tp

I got the list of files from the following git grep command:

git grep -Pl 'from \..+import|import \.' **/*.pxd **/*.pyx **/*.tp 

Activity

  1. added
    Meta-issue
    on Oct 2, 2025
  2. dipak0000812 commented on Oct 2, 2025

    @dipak0000812
    Contributor

    Hi! I'm working on sklearn/utils/_fast_dict.pyx

  3. Ganasekhar-gif commented on Oct 2, 2025

    @Ganasekhar-gif
    Contributor

    can i take this one sklearn/ensemble/_gradient_boosting.pyx

  4. lesteve commented on Oct 2, 2025

    @lesteve
    MemberAuthor

    @Ganasekhar-gif @dipak0000812 so this issue is meant for people that attend the PyData sprint today. Will you be at the sprint?

    Just curious how did you bump into this issue?

    • complete chance
    • you are registered to a service that sends you notifications for issue to work on on open-source repos. I would be interested to know which one(s).
    • you are using your own automation tool to find issue to work on. More details would be appreciated 🙏.
    • some other way: please give a few more details 🙏
  5. dipak0000812 commented on Oct 2, 2025

    @dipak0000812
    Contributor

    Hi @lesteve!

    I apologize for the confusion. I am not physically at the PyData Paris sprint. I found this issue through complete chance while browsing scikit-learn issues looking for beginner-friendly contributions to make my first open source contribution.

    I missed the warning at the top that said "Please refrain from working on this issue if you are not physically at the sprint." I'm sorry for jumping in without reading that carefully.

    I understand this issue was reserved for sprint participants. Should I close this PR? I'm happy to do so if it's more appropriate for someone at the sprint to work on it.

    Again, apologies for the oversight, and thank you for your understanding!

  6. Ganasekhar-gif commented on Oct 2, 2025

    @Ganasekhar-gif
    Contributor

    @lesteve Thanks for clarifying! I’m not attending the PyData sprint.

    I’ve been actively looking for open issues in Scikit-learn to contribute to, and I came across this one while browsing the repo’s issue tracker.

    If this issue is reserved for sprint participants only, I completely understand and I’ll step aside. Otherwise, I’d be happy to work on it.

  7. lesteve commented on Oct 2, 2025

    @lesteve
    MemberAuthor

    Thanks for the details @dipak0000812 @Ganasekhar-gif I appreciate it 🙏. Interesting that by pure chance two persons arrive a few hours after I opened the issue but maybe this is to be expected with a reasonably popular repo like scikit-learn 🤷.

    I mean now that you are here, feel free to work on the files you mentioned but please don't open another PRs. In a few days we will see how many of the files have been tackled and it will be open for all contributors.

  8. dipak0000812 commented on Oct 2, 2025

    @dipak0000812
    Contributor

    Thank you so much @lesteve for your understanding! I really appreciate the opportunity to contribute.

    I'll wait for this PR to be reviewed and won't open any additional PRs until the sprint period is over. Looking forward to contributing more to scikit-learn in the future!

  9. fabarca commented on Oct 2, 2025

    @fabarca
    Contributor

    I will work on this file: sklearn/ensemble/_hist_gradient_boosting/_gradient_boosting.pyx

  10. basilegithub commented on Oct 2, 2025

    @basilegithub
    Contributor

    I will be working on sklearn/metrics/_pairwise_distances_reduction/_base.pxd.tp

  11. rvraghvender commented on Oct 2, 2025

    @rvraghvender
    Contributor

    I am gonna work on this file "sklearn/utils/sparsefuncs_fast.pyx"

  12. xuzhang0327 commented on Oct 2, 2025

    @xuzhang0327
    Contributor

    i will be working on this file "sklearn/linear_model/_cd_fast.pyx"

  13. 58 remaining items

  14. Jongwan93 commented on Oct 8, 2025

    @Jongwan93
    Contributor

    Hello I'd like to work on
    sklearn/utils/_fast_dict.pxd

  15. Nithurshen commented on Oct 8, 2025

    @Nithurshen
    Contributor

    It has been worked on, I have checked it.

  16. Jongwan93 commented on Oct 8, 2025

    @Jongwan93
    Contributor

    my bad. just ran git grep command.
    Working on:
    sklearn/metrics/_pairwise_distances_reduction/_datasets_pair.pxd.tp (#32444)

  17. Jongwan93 commented on Oct 8, 2025

    @Jongwan93
    Contributor

    I will also be working on:
    sklearn/metrics/_pairwise_distances_reduction/_datasets_pair.pyx.tp

  18. aaron-seq commented on Oct 8, 2025

    @aaron-seq

    Actually, I'd like to work on sklearn/metrics/_pairwise_distances_reduction/_argkmin.pxd.tp instead

  19. aaron-seq commented on Oct 8, 2025

    @aaron-seq

    Hi! I'd like to work on sklearn/metrics/cluster/_expected_mutual_info_fast.pyx

  20. Dex947 commented on Oct 9, 2025

    @Dex947
    Contributor

    I'll work on sklearn/metrics/_pairwise_distances_reduction/_base.pxd.tp

  21. Dex947 commented on Oct 9, 2025

    @Dex947
    Contributor

    I'll work on sklearn/cluster/_hdbscan/_tree.pxd

  22. Dex947 commented on Oct 9, 2025

    @Dex947
    Contributor

    I'll work on sklearn/metrics/cluster/_expected_mutual_info_fast.pyx

  23. Nithurshen commented on Oct 10, 2025

    @Nithurshen
    Contributor

    I'll work on sklearn/svm/_liblinear.pyx

  24. added a commit that references this issue on Oct 10, 2025
    fb302e3
  25. mahdiabid91 commented on Oct 10, 2025

    @mahdiabid91
    Contributor

    working on sklearn/metrics/_pairwise_distances_reduction/_argkmin_classmode.pyx.tp

  26. basilegithub commented on Oct 10, 2025

    @basilegithub
    Contributor

    Working on " sklearn/metrics/_pairwise_distances_reduction/_argkmin.pxd.tp"

  27. lesteve commented on Oct 10, 2025

    @lesteve
    MemberAuthor

    Thanks everyone, it looks like all our Cython code is now using absolute imports!

    Quick poll out of curiosity, can you use reactions on this post to explain how you discovered this issue and decided to work on it:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Meta-issuegood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions