Skip to content

Remove _most_ of import_utils.py#6599

Merged
rapids-bot[bot] merged 15 commits intorapidsai:branch-25.06from
jcrist:remove-dead-code-import-utils
Apr 29, 2025
Merged

Remove _most_ of import_utils.py#6599
rapids-bot[bot] merged 15 commits intorapidsai:branch-25.06from
jcrist:remove-dead-code-import-utils

Conversation

@jcrist
Copy link
Copy Markdown
Member

@jcrist jcrist commented Apr 28, 2025

This PR started because I noticed most of the functions in import_utils.py were effectively dead code. It spiraled out a bit from there to remove almost all of import_utils.py in favor of:

  • Using pytest.importorskip to handle conditional imports in tests. This is the proper pytest pattern to do this, and is both easier to get correct and uses fewer lines of code.
  • Localized import checks (see hdbscan.pyx). Keeping the import check local to the module is easier to read IMO, and also helps avoid dead code accumulating in a global utils file.
  • No import checks. Things like cupy are required dependencies and don't need to be gated at all.

The remaining functions will be removed in other PRs:

@jcrist jcrist requested a review from a team as a code owner April 28, 2025 19:01
@jcrist jcrist requested review from dantegd and viclafargue April 28, 2025 19:01
@github-actions github-actions Bot added the Cython / Python Cython or Python issue label Apr 28, 2025
@jcrist jcrist added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Apr 28, 2025
@jcrist jcrist self-assigned this Apr 28, 2025
@jcrist jcrist force-pushed the remove-dead-code-import-utils branch from e5fb166 to 25187fc Compare April 29, 2025 13:52
Comment thread python/cuml/cuml/dask/common/utils.py
Comment thread python/cuml/cuml/tests/explainer/test_gpu_treeshap.py
@csadorf
Copy link
Copy Markdown
Contributor

csadorf commented Apr 29, 2025

/merge

@rapids-bot rapids-bot Bot merged commit ebd79eb into rapidsai:branch-25.06 Apr 29, 2025
74 checks passed
@jcrist jcrist deleted the remove-dead-code-import-utils branch April 29, 2025 18:25
Ofek-Haim pushed a commit to Ofek-Haim/cuml that referenced this pull request May 13, 2025
This PR started because I noticed most of the functions in `import_utils.py` were effectively dead code. It spiraled out a bit from there to remove _almost all_ of `import_utils.py` in favor of:

- Using `pytest.importorskip` to handle conditional imports in tests. This is the proper `pytest` pattern to do this, and is both easier to get correct and uses fewer lines of code.
- Localized import checks (see `hdbscan.pyx`). Keeping the import check local to the module is easier to read IMO, and also helps avoid dead code accumulating in a global utils file.
- No import checks. Things like `cupy` are required dependencies and don't need to be gated at all.

The remaining functions will be removed in other PRs:

- `has_dask` will go away once `dask` is made optional (see rapidsai#5934)
- `has_scipy` is removed in rapidsai#6596
- `has_sklearn` will go away once `sklearn` is made a required dependency

Authors:
  - Jim Crist-Harif (https://github.com/jcrist)

Approvers:
  - Simon Adorf (https://github.com/csadorf)

URL: rapidsai#6599
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Cython / Python Cython or Python issue improvement Improvement / enhancement to an existing function non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants