Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MNT Avoid numpy array shape DeprecationWarnings in datasets - #34740

Merged
lesteve merged 1 commit into
scikit-learn:mainfrom
ethanglaser:dev/eglaser-shape-depr-resolution
Aug 13, 2026
Merged

MNT Avoid numpy array shape DeprecationWarnings in datasets#34740
lesteve merged 1 commit into
scikit-learn:mainfrom
ethanglaser:dev/eglaser-shape-depr-resolution

Conversation

@ethanglaser

@ethanglaser ethanglaser commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

N/A

What does this implement/fix? Explain your changes.

Scikit-learn suppresses DeprecationWarnings, but in downstream examples in scikit-learn-intelex we run examples with -W error to keep user-facing examples clean. With numpy 2.5+, setting shape on numpy array was deprecated. Simplest reproducer (py3.12+):

pip install scikit-learn==1.9.0 numpy==2.5.2
python -W error -c "from sklearn.datasets import load_digits; load_digits()"

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/mnt/cached_oses/eglaser/miniforge3/envs/sklearn_bug/lib/python3.12/site-packages/sklearn/utils/_param_validation.py", line 218, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/cached_oses/eglaser/miniforge3/envs/sklearn_bug/lib/python3.12/site-packages/sklearn/datasets/_base.py", line 1007, in load_digits
    images.shape = (-1, 8, 8)
    ^^^^^^^^^^^^
DeprecationWarning: Setting the shape on a NumPy array has been deprecated in NumPy 2.5.
As an alternative, you can create a new view using np.reshape (with copy=False if needed).

First time contributor introduction

I am a developer working on https://github.com/uxlfoundation/scikit-learn-intelex

AI usage disclosure

I used AI assistance for:

  • Research and understanding

Any other comments?

N/A

@github-actions

Copy link
Copy Markdown

Thank you for opening your first pull request to scikit-learn! 🎉

To help get your contribution reviewed, please make sure that:

  • You have filled out the pull request template.

  • The pull request addresses an existing issue that is ready for contribution (e.g. not tagged as 'Needs Triage', 'Needs Decision', ...). If you are proposing a new feature, please open an issue to discuss it first.

  • There are no other open pull requests already targeting the same issue.

  • You have followed the pull request checklist. In particular, linting and tests should pass.

@ethanglaser ethanglaser changed the title Address setting np array shape DeprecationWarnings MNT Address setting np array shape DeprecationWarnings Aug 12, 2026
@lesteve

lesteve commented Aug 13, 2026

Copy link
Copy Markdown
Member

Thanks for the PR!

I am guessing we didn't catch this in our tests, because:

  • most CI builds don't run the datasets tests i.e. SKLEARN_SKIP_NETWORK_TESTS=1
  • the one that do run datasets tests don't turn warnings into errors, i.e. they don't set SKLEARN_WARNINGS_AS_ERRORS=1.

@lesteve lesteve 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, thanks!

The changes look fine and for good measure I did run the datasets tests with an empty ~/scikit_learn_data cache with

SKLEARN_SKIP_NETWORK_TESTS=0 pytest sklearn/datasets/tests/

@lesteve lesteve changed the title MNT Address setting np array shape DeprecationWarnings MNT Avoid numpy array shape DeprecationWarnings in datasets Aug 13, 2026
@lesteve
lesteve merged commit e4ae38e into scikit-learn:main Aug 13, 2026
45 checks passed
prady0t pushed a commit to prady0t/scikit-learn that referenced this pull request Sep 2, 2026
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 8, 2026
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 9, 2026
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 9, 2026
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.

2 participants