Repository navigation
MNT Replace np.isfortran that is deprecated in numpy-dev - #35304
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| def is_c_contiguous(a): | ||
| return np.isfortran(a.T) |
There was a problem hiding this comment.
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.
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]>
| def is_c_contiguous(a): | ||
| return np.isfortran(a.T) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😜.
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]>

Reference Issues/PRs
Fixes #35289
What does this implement/fix? Explain your changes.
np.isfortranis deprecated in numpy-dev (numpy/numpy#32722), which makes the scipy-dev CI fail. This replaces its 3 uses:predict_stagesin_gradient_boosting.pyx(the cause of almost all the failures):X.flags.fnc, the replacement suggested by numpy, same semantics.flags.c_contiguous/flags.f_contiguous, which say what the tests check.Locally, with numpy
2.6.0.dev0and-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:
🤖 Generated with Claude Code