Skip to content

MNT Replace np.isfortran that is deprecated in numpy-dev - #35304

Merged
lesteve merged 1 commit into
scikit-learn:mainfrom
cakedev0:mnt-numpy-isfortran-deprecation
Nov 3, 2026
Merged

lesteve merged 1 commit into
scikit-learn:mainfrom
cakedev0:mnt-numpy-isfortran-deprecation

Conversation

@cakedev0

@cakedev0 cakedev0 commented Nov 2, 2026

Copy link
Copy Markdown
Member

Reference Issues/PRs

Fixes #35289

What does this implement/fix? Explain your changes.

np.isfortran is deprecated in numpy-dev (numpy/numpy#32722), which makes the scipy-dev CI fail. This replaces its 3 uses:

  • predict_stages in _gradient_boosting.pyx (the cause of almost all the failures): X.flags.fnc, the replacement suggested by numpy, same semantics.
  • 2 tests: flags.c_contiguous / flags.f_contiguous, which say what the tests check.

Locally, with numpy 2.6.0.dev0 and -W error:numpy.isfortran:DeprecationWarning, the test modules from the issue pass. The commit has [scipy-dev] so the scipy-dev CI runs here too.

AI usage disclosure

I used AI assistance for:

  • Code generation (trivial change)

🤖 Generated with Claude Code

Comment on lines -46 to -47
def is_c_contiguous(a):
return np.isfortran(a.T)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

quite weird 😂

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.

Quickly doing some code archaeology seems like the first instance was added in 2018 #12251

Seems like an historical quirk, I guess this has some edge cases in 1d cases, (n_rows, 1) or (1, n_features) shapes?

I think we are outside these edge cases, so we are fine.

@cakedev0
cakedev0 marked this pull request as ready for review November 2, 2026 23:04
cakedev0 added a commit to cakedev0/my-scikit-learn-backlog that referenced this pull request Nov 2, 2026
done: Benchmarks: answer Vika-F and david-cortes-intel on [benchmarks#129](probabl-ai/scikit-learn-benchmarks#129) (sklearnex TBB threads not limited under joblib; since 2026-10-08)
done: Benchmarks: tell david-cortes-intel whether the OMP runtime issue still happens with the latest conda-forge packages, on [benchmarks#93](probabl-ai/scikit-learn-benchmarks#93) (Anaconda in the envs matrix; since 2026-10-09)
add: Maintenance: get [sklearn#35304](scikit-learn/scikit-learn#35304) merged (replace the deprecated `np.isfortran`, fixes [sklearn#35289](scikit-learn/scikit-learn#35289))

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@virchan virchan 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, @cakedev0!

[scipy-dev] is green. @lesteve, would you like to have a look?

@virchan virchan added the Waiting for Second Reviewer First reviewer is done, need a second one! label Nov 3, 2026
Comment on lines -46 to -47
def is_c_contiguous(a):
return np.isfortran(a.T)

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.

Quickly doing some code archaeology seems like the first instance was added in 2018 #12251

Seems like an historical quirk, I guess this has some edge cases in 1d cases, (n_rows, 1) or (1, n_features) shapes?

I think we are outside these edge cases, so we are fine.

# Test that if X is fortran ordered it stays
X = np.asfortranarray(X)
assert np.isfortran(as_float_array(X, copy=True))
assert as_float_array(X, copy=True).flags.f_contiguous

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.

np.isfortran checks that the array is F-contiguous and not C-contiguous, but since we are in non-degenerate 2d cases (i.e. n_samples>1 and n_features>1), this is probably fine.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure to understand what you mean because:

image

@lesteve lesteve Nov 3, 2026 •

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 was trying to say np.isfortran(arr) is more picky than arr.flags.f_contiguous, you need to be F-contiguous but not C-contiguous. I don't think this matters in this test though.

In [1]: import numpy as np

In [2]: a = np.array([1, 2, 3])

In [3]: b = a.reshape(-1, 1)

In [4]: c = a.reshape(1, -1)

In [5]: np.isfortran(a)
Out[5]: False

In [6]: np.isfortran(b)
Out[6]: False

In [7]: np.isfortran(c)
Out[7]: False

Friend don't let friends share screenshots of code, I am sure agents can transform easily a screenshot into a copy-pastable snippet 😜.

@lesteve lesteve changed the title MNT Replace deprecated np.isfortran MNT Replace np.isfortran that is deprecated in numpy-dev Nov 3, 2026
@lesteve
lesteve merged commit 8136d4b into scikit-learn:main Nov 3, 2026
53 of 54 checks passed
cakedev0 added a commit to cakedev0/my-scikit-learn-backlog that referenced this pull request Nov 3, 2026
done: Maintenance: get [sklearn#35304](scikit-learn/scikit-learn#35304) merged (replace the deprecated `np.isfortran`, fixes [sklearn#35289](scikit-learn/scikit-learn#35289))
todo: move [sklearn#35216](scikit-learn/scikit-learn#35216) from Waiting to Now: add the non-regression test lesteve asks for
add: Upstream: dpnp reports [IntelPython/dpnp#3149](IntelPython/dpnp#3149) (slow `X @ w` on C-contiguous tall matrices) and [IntelPython/dpnp#3148](IntelPython/dpnp#3148) (scalar operands synchronize the queue)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

⚠️ CI failed on Unit tests Linux x86-64 pylatest_pip_scipy_dev (last failure: Nov 03, 2026) ⚠️

3 participants