Control: severity -1 serious Control: tags -1 + patch Please see attached patch from Ubuntu for this issue.
Description: Scipy 1.8.0 compat: copy private classes into dask/array/stats.py (#8694) Origin: upstream, https://github.com/dask/dask/commit/a27b437da2594fd5c15f85736aa520feb726ddbd Author: Julia Signell <jsign...@gmail.com> Last-Update: 2022-03-03
--- a/dask/array/stats.py +++ b/dask/array/stats.py @@ -28,6 +28,7 @@ # out of the use of this software, even if advised of the possibility of # such damage. import math +from collections import namedtuple import numpy as np @@ -42,16 +43,27 @@ raise ImportError("`dask.array.stats` requires `scipy` to be installed.") from e from scipy import special from scipy.stats import distributions -from scipy.stats.stats import ( - F_onewayResult, - KurtosistestResult, - NormaltestResult, - Power_divergenceResult, - SkewtestResult, - Ttest_1sampResult, - Ttest_indResult, - Ttest_relResult, -) + +# copied from https://github.com/scipy/scipy/blob/v1.8.0/scipy/stats/_stats_py.py since +# these are all private after v1.8.0 +F_onewayResult = namedtuple("F_onewayResult", ("statistic", "pvalue")) +KurtosistestResult = namedtuple("KurtosistestResult", ("statistic", "pvalue")) +NormaltestResult = namedtuple("NormaltestResult", ("statistic", "pvalue")) +Power_divergenceResult = namedtuple("Power_divergenceResult", ("statistic", "pvalue")) +SkewtestResult = namedtuple("SkewtestResult", ("statistic", "pvalue")) +Ttest_1sampResult = namedtuple("Ttest_1sampResult", ("statistic", "pvalue")) +Ttest_indResult = namedtuple("Ttest_indResult", ("statistic", "pvalue")) +Ttest_relResult = namedtuple("Ttest_relResult", ("statistic", "pvalue")) + +# Map from names to lambda_ values used in power_divergence(). +_power_div_lambda_names = { + "pearson": 1, + "log-likelihood": 0, + "freeman-tukey": -0.5, + "mod-log-likelihood": -1, + "neyman": -2, + "cressie-read": 2 / 3, +} __all__ = [ "ttest_ind", @@ -140,14 +152,13 @@ def power_divergence(f_obs, f_exp=None, ddof=0, axis=0, lambda_=None): if isinstance(lambda_, str): - # TODO: public api - if lambda_ not in scipy.stats.stats._power_div_lambda_names: - names = repr(list(scipy.stats.stats._power_div_lambda_names.keys()))[1:-1] + if lambda_ not in _power_div_lambda_names: + names = repr(list(_power_div_lambda_names.keys()))[1:-1] raise ValueError( f"invalid string for lambda_: {lambda_!r}. " f"Valid strings are {names}" ) - lambda_ = scipy.stats.stats._power_div_lambda_names[lambda_] + lambda_ = _power_div_lambda_names[lambda_] elif lambda_ is None: lambda_ = 1 --- a/dask/array/tests/test_linearoperator.py +++ /dev/null @@ -1,31 +0,0 @@ -import pytest - -pytest.importorskip("scipy") - -import numpy as np -import scipy.sparse.linalg - -import dask.array as da - - -def test_LinearOperator(): - X = np.random.random(size=(3, 2)) - y = np.random.random(size=(2, 1)) - w = np.random.random(size=(3, 1)) - square = np.random.random(size=(2, 2)) - - dX = da.from_array(X, chunks=(2, 1)) - - npLO = scipy.sparse.linalg.aslinearoperator(X) - daLO = scipy.sparse.linalg.interface.MatrixLinearOperator(dX) - - functions = [lambda x, y: x.matvec(y), lambda x, y: x * y, lambda x, y: x.dot(y)] - for func in functions: - assert np.allclose(func(npLO, y), func(daLO, y)) - - assert np.allclose(npLO.matmat(square), daLO.matmat(square)) - - assert np.allclose(npLO.rmatvec(w), daLO.rmatvec(w)) - - assert npLO.dtype == daLO.dtype - assert npLO.shape == daLO.shape --- a/docs/source/array-linear-operator.rst +++ /dev/null @@ -1,28 +0,0 @@ -LinearOperator -============== - -Dask Array implements the SciPy LinearOperator_ interface and it can be used -with any SciPy algorithm depending on that interface. - -Example -------- - -.. code-block:: python - - import dask.array as da - x = da.random.random(size=(10000, 10000), chunks=(1000, 1000)) - - from scipy.sparse.linalg.interface import MatrixLinearOperator - A = MatrixLinearOperator(x) - - import numpy as np - b = np.random.random(10000) - - from scipy.sparse.linalg import gmres - x = gmres(A, b) - -*Disclaimer: This is just a toy example and not necessarily the best way to -solve this problem for this data.* - - -.. _LinearOperator: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.LinearOperator.html --- a/docs/source/array-overlap.rst +++ b/docs/source/array-overlap.rst @@ -114,7 +114,7 @@ .. code-block:: python - >>> from scipy.ndimage.filters import gaussian_filter + >>> from scipy.ndimage import gaussian_filter >>> def func(block): ... return gaussian_filter(block, sigma=1) --- a/docs/source/array.rst +++ b/docs/source/array.rst @@ -12,7 +12,6 @@ array-design.rst array-sparse.rst array-stats.rst - array-linear-operator.rst array-slicing.rst array-assignment.rst array-stack.rst