has2k1 / scikit-misc

Miscellaneous tools for data analysis and scientific computing
https://has2k1.github.io/scikit-misc/stable
BSD 3-Clause "New" or "Revised" License
37 stars 9 forks source link

Is NumPy >= 2.0 now a hard requirement? #35

Closed penguinpee closed 4 months ago

penguinpee commented 4 months ago

With the latest release, it appears the wheel is build against NumPy >= 2.0, going by the comment in pyproject.toml:

https://github.com/has2k1/scikit-misc/blob/556c22ff46ed1b39fc4bdbb5180f2a2bb7dcd138/pyproject.toml#L82-L87

In Fedora, we are not yet ready for a major upgrade of NumPy. When building against NumPy 1.26.4 with Python 3.13.0b2 or Python 3.12.3, tests are failing. The build itself completes (with a couple of warnings).

Test failures with NumPy 1.26.4 ```python =================================== FAILURES =================================== ______________________ TestLoess2d.test_2d_pred_nostderr _______________________ self = def test_2d_pred_nostderr(self): "2D prediction - no stderr" (x, y, results, newdata1, _) = self.d madeup = loess(x, y) madeup.model.span = 0.5 madeup.model.normalize = True > prediction = madeup.predict(newdata1, stderror=False) tests/test_loess.py:127: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _loess.pyx:973: in _loess.loess.predict ??? _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > ??? E TypeError: asarray() got an unexpected keyword argument 'copy' _loess.pyx:683: TypeError _______________________ TestLoess2d.test_2d_pred_nodata ________________________ self = def test_2d_pred_nodata(self): "2D prediction - nodata" (x, y, _, _, _) = self.d madeup = loess(x, y) try: > madeup.predict(None) tests/test_loess.py:138: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _loess.pyx:973: in _loess.loess.predict ??? _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > ??? E TypeError: asarray() got an unexpected keyword argument 'copy' _loess.pyx:683: TypeError _______________________ TestLoess2d.test_2d_pred_stderr ________________________ self = def test_2d_pred_stderr(self): "2D prediction - w/ stderr" (x, y, results, _, newdata2) = self.d madeup = loess(x, y) madeup.model.span = 0.5 madeup.model.normalize = True > prediction = madeup.predict(newdata2, stderror=True) tests/test_loess.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _loess.pyx:973: in _loess.loess.predict ??? _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > ??? E TypeError: asarray() got an unexpected keyword argument 'copy' _loess.pyx:683: TypeError _______________________ TestLoess2d.test_2d_pred_confinv _______________________ self = def test_2d_pred_confinv(self): "2D prediction - confidence" (x, y, results, _, newdata2) = self.d madeup = loess(x, y) madeup.model.span = 0.5 madeup.model.normalize = True > prediction = madeup.predict(newdata2, stderror=True) tests/test_loess.py:169: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _loess.pyx:973: in _loess.loess.predict ??? _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > ??? E TypeError: asarray() got an unexpected keyword argument 'copy' _loess.pyx:683: TypeError _________________________ TestLoessGas.test_1dpredict __________________________ self = def test_1dpredict(self): "Basic test 1d - prediction" (E, NOx, gas_fit_E, _, _, results) = self.d gas = loess(E, NOx, span=2./3.) gas.fit() > predicted = gas.predict(gas_fit_E, stderror=False).values tests/test_loess.py:206: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _loess.pyx:973: in _loess.loess.predict ??? _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > ??? E TypeError: asarray() got an unexpected keyword argument 'copy' _loess.pyx:683: TypeError ________________________ TestLoessGas.test_1dpredict_2 _________________________ self = def test_1dpredict_2(self): "Basic test 1d - new predictions" (E, NOx, _, newdata, _, results) = self.d # gas = loess(E, NOx, span=2./3.) gas = loess(E, NOx) gas.model.span = 2./3. > prediction = gas.predict(newdata, stderror=True) tests/test_loess.py:215: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _loess.pyx:973: in _loess.loess.predict ??? _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > ??? E TypeError: asarray() got an unexpected keyword argument 'copy' _loess.pyx:683: TypeError __________________________ TestLoessGas.test_failures __________________________ self = def test_failures(self): "Tests failures" (E, NOx, gas_fit_E, _, _, _) = self.d gas = loess(E, NOx, span=2./3.) # This one should fail (all parametric) gas.model.parametric = True with pytest.raises(ValueError): gas.fit() # This one also (all drop_square) gas.model.drop_square = True with pytest.raises(ValueError): gas.fit() gas.model.degree = 1 with pytest.raises(ValueError): gas.fit() # This one should not (revert to std) gas.model.parametric = False gas.model.drop_square = False gas.model.degree = 2 gas.fit() # Now, for predict ................. > prediction = gas.predict(gas_fit_E, stderror=False) tests/test_loess.py:260: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _loess.pyx:973: in _loess.loess.predict ??? _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > ??? E TypeError: asarray() got an unexpected keyword argument 'copy' _loess.pyx:683: TypeError __________________________ TestLoessGas.test_pickling __________________________ self = def test_pickling(self): rs = np.random.RandomState(seed=123) n = 500 np.arange(n) x = np.linspace(0, 500, n) y = rs.randint(1, 1000, n) lo = loess(y, x, span=0.3) lo.fit() # pickle lo, unpickle it as lo2 and compare # predictions from both with tempfile.TemporaryFile() as f: pickle.dump(lo, f) f.seek(0) lo2 = pickle.load(f) > npt.assert_array_equal(lo.predict(x).values, lo2.predict(x).values) tests/test_loess.py:284: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _loess.pyx:973: in _loess.loess.predict ??? _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > ??? E TypeError: asarray() got an unexpected keyword argument 'copy' _loess.pyx:683: TypeError ```
musicinmybrain commented 4 months ago

Note that we (Fedora) don’t need to build wheels that are compatible with both Numpy 2.x and Numpy 1.x, since the distribution package is used only with the distribution’s Numpy.

I am about to open a PR that seems to fix backwards-compatibility with Numpy 1.x. I think this will also matter for PyPI users using the latest wheels with Numpy 1.x, since the test failures reflect an API-level incompatibility with Numpy 1.x.