AllenInstitute / mouse_connectivity_models

Python package providing mesoscale connectivity models for mouse.
http://mouse-connectivity-models.readthedocs.io/en/latest/
Other
39 stars 15 forks source link

nonnegative_linear component test results in an error during pytest #47

Closed keiko-fujii closed 4 years ago

keiko-fujii commented 4 years ago

Hello, I got an error during pytest. Do you know how to solve the following error? I am using python3.7 on MacOS Catalina.

=================================================== test session starts ====================================================
platform darwin -- Python 3.7.4, pytest-5.3.5, py-1.8.1, pluggy-0.13.1
rootdir: /Users/kfujii2/projects/Allen_injection_site_analysis/Reimann_etal/mouse_connectivity_models
collected 109 items

mouse_connectivity_models/mcmodels/core/tests/test_base.py .....                                                     [  4%]
mouse_connectivity_models/mcmodels/core/tests/test_experiment.py .......                                             [ 11%]
mouse_connectivity_models/mcmodels/core/tests/test_masks.py ..........                                               [ 20%]
mouse_connectivity_models/mcmodels/core/tests/test_utils.py ..                                                       [ 22%]
mouse_connectivity_models/mcmodels/core/tests/test_voxel_model_api.py ........                                       [ 29%]
mouse_connectivity_models/mcmodels/core/tests/test_voxel_model_cache.py ...........                                  [ 39%]
mouse_connectivity_models/mcmodels/models/homogeneous/tests/test_homogeneous_model.py ...                            [ 42%]
mouse_connectivity_models/mcmodels/models/homogeneous/tests/test_subset_selection.py ...                             [ 44%]
mouse_connectivity_models/mcmodels/models/voxel/tests/test_regionalized_model.py .......                             [ 51%]
mouse_connectivity_models/mcmodels/models/voxel/tests/test_voxel_connectivity_array.py .................             [ 66%]
mouse_connectivity_models/mcmodels/models/voxel/tests/test_voxel_model.py ....                                       [ 70%]
mouse_connectivity_models/mcmodels/regressors/nonnegative_linear/tests/test_base.py .F..                             [ 74%]
mouse_connectivity_models/mcmodels/regressors/nonnegative_linear/tests/test_ridge.py .F.                             [ 77%]
mouse_connectivity_models/mcmodels/regressors/nonparametric/tests/test_kernels.py .......                            [ 83%]
mouse_connectivity_models/mcmodels/regressors/nonparametric/tests/test_nadaraya_watson.py ............               [ 94%]
mouse_connectivity_models/mcmodels/tests/test_utils.py ......                                                        [100%]

========================================================= FAILURES =========================================================
_______________________________________________ test_nonnegative_regression ________________________________________________

    def test_nonnegative_regression():
        # ------------------------------------------------------------------------
        # test shape incompatibility
        X, y = np.ones((10, 1)), np.ones((11, 1))

        assert_raises(ValueError, nonnegative_regression, X, y)

        # ------------------------------------------------------------------------
        # test X.ndim != 2
        X = np.linspace(-10, 10, 100)
        y = 4*X

        assert_raises(ValueError, nonnegative_regression, X, y)

        # ------------------------------------------------------------------------
        # test function output
        X = X.reshape(-1, 1)

        coef, res = nonnegative_regression(X, y)

        assert_allclose(coef[0], 4.)
        assert_allclose(res[0], 0.0, atol=1e-10)

        # ------------------------------------------------------------------------
        # test sample_weight
        sample_weight = 1.0

        coef, res = nonnegative_regression(X, y)
        coef_sw, res_sw = nonnegative_regression(X, y, sample_weight)

        assert_array_almost_equal(coef.ravel(), coef_sw)
        assert_array_almost_equal(res, res_sw)

        # ------------------------------------------------------------------------
        # test sample_weight shape incompatibility
        sample_weight = np.ones(11)

>       assert_raises(ValueError, nonnegative_regression, X, y, sample_weight)

mouse_connectivity_models/mcmodels/regressors/nonnegative_linear/tests/test_base.py:67:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py:756: in assertRaises
    return context.handle('assertRaises', args, kwargs)
/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py:178: in handle
    callable_obj(*args, **kwargs)
/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py:201: in __exit__
    self.obj_name))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <unittest.case._AssertRaisesContext object at 0x1401bd8d0>
standardMsg = 'ValueError not raised by nonnegative_regression'

    def _raiseFailure(self, standardMsg):
        msg = self.test_case._formatMessage(self.msg, standardMsg)
>       raise self.test_case.failureException(msg)
E       AssertionError: ValueError not raised by nonnegative_regression

/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py:135: AssertionError
____________________________________________ test_nonnegative_ridge_regression _____________________________________________

    def test_nonnegative_ridge_regression():
        # ------------------------------------------------------------------------
        # test shape incompatibility
        X, y = np.ones((10, 1)), np.ones((11, 1))
        alpha = np.zeros(1)

        assert_raises(ValueError, nonnegative_ridge_regression, X, y, alpha)

        # ------------------------------------------------------------------------
        # test X.ndim != 2
        X = np.linspace(-10, 10, 100)
        y = 4*X

        assert_raises(ValueError, nonnegative_ridge_regression, X, y, alpha)

        # ------------------------------------------------------------------------
        # test incompatible alpha shape
        X = X.reshape(-1, 1)
        alpha = np.zeros(2)

        assert_raises(ValueError, nonnegative_ridge_regression, X, y, alpha)

        # ------------------------------------------------------------------------
        # test sample_weight
        alpha = np.arange(X.shape[1])
        sample_weight = 1.0

        coef, res = _solve_ridge_nnls(X, y.reshape(-1, 1), alpha, 'SLSQP')
        coef_sw, res_sw = nonnegative_ridge_regression(X, y, alpha, sample_weight)

        assert_array_almost_equal(coef.ravel(), coef_sw)
        assert_array_almost_equal(res, res_sw)

        # ------------------------------------------------------------------------
        # test sample_weight shape incompatibility
        sample_weight = np.ones(11)

>       assert_raises(ValueError, nonnegative_ridge_regression, X, y, alpha, sample_weight)

mouse_connectivity_models/mcmodels/regressors/nonnegative_linear/tests/test_ridge.py:61:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py:756: in assertRaises
    return context.handle('assertRaises', args, kwargs)
/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py:178: in handle
    callable_obj(*args, **kwargs)
/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py:201: in __exit__
    self.obj_name))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <unittest.case._AssertRaisesContext object at 0x140350810>
standardMsg = 'ValueError not raised by nonnegative_ridge_regression'

    def _raiseFailure(self, standardMsg):
        msg = self.test_case._formatMessage(self.msg, standardMsg)
>       raise self.test_case.failureException(msg)
E       AssertionError: ValueError not raised by nonnegative_ridge_regression

/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py:135: AssertionError
===================================================== warnings summary =====================================================
/usr/local/lib/python3.7/site-packages/sklearn/utils/deprecation.py:144
  /usr/local/lib/python3.7/site-packages/sklearn/utils/deprecation.py:144: FutureWarning: The sklearn.linear_model.base module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.linear_model. Anything that cannot be imported from sklearn.linear_model is now part of the private API.
    warnings.warn(message, FutureWarning)

/usr/local/lib/python3.7/site-packages/sklearn/utils/deprecation.py:144
  /usr/local/lib/python3.7/site-packages/sklearn/utils/deprecation.py:144: FutureWarning: The sklearn.metrics.scorer module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.metrics. Anything that cannot be imported from sklearn.metrics is now part of the private API.
    warnings.warn(message, FutureWarning)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
======================================== 2 failed, 107 passed, 2 warnings in 1.55s =========================================
kamdh commented 4 years ago

Hi, I'm afraid we do not support OS X. I suggest trying on a Linux machine and seeing if it works, or starting from a fresh python install/environment. Best of luck

keiko-fujii commented 4 years ago

Thanks for your answer. I will try with another computer.