Repository navigation
Description
Looks like Scipy modify what is accepted as popmean in scipy.stats.ttest_1samp
popmean:float or array_like
Expected value in null hypothesis. If array_like, then it must have the same shape as a excluding the axis dimension.
popmean:float or array_like
Expected value in null hypothesis. If array_like, then its length along axis must equal 1, and it must otherwise be broadcastable with a.
To enforce that, they are doing a `np.squeeze(popmean, axis=axis) and we are getting a raise
E ValueError: `popmean.shape[axis]` must equal 1.
In our test
dask/dask/array/tests/test_stats.py
Lines 65 to 98 in 982376e
| @pytest.mark.parametrize( | |
| "kind, kwargs", | |
| [ | |
| ("ttest_ind", {}), | |
| ("ttest_ind", {"equal_var": False}), | |
| ("ttest_1samp", {}), | |
| ("ttest_rel", {}), | |
| ("chisquare", {}), | |
| ("power_divergence", {}), | |
| ("power_divergence", {"lambda_": 0}), | |
| ("power_divergence", {"lambda_": -1}), | |
| ("power_divergence", {"lambda_": "neyman"}), | |
| ], | |
| ) | |
| def test_two(kind, kwargs): | |
| # The sums of observed and expected frequencies must match | |
| a = np.random.random(size=30) | |
| b = a[::-1] | |
| a_ = da.from_array(a, 3) | |
| b_ = da.from_array(b, 3) | |
| dask_test = getattr(dask.array.stats, kind) | |
| scipy_test = getattr(scipy.stats, kind) | |
| with warnings.catch_warnings(): # maybe overflow warning (power_divergence) | |
| warnings.simplefilter("ignore", category=RuntimeWarning) | |
| result = dask_test(a_, b_, **kwargs) | |
| expected = scipy_test(a, b, **kwargs) | |
| assert isinstance(result, Delayed) | |
| assert allclose(result.compute(), expected) | |
| # fails occasionally. shouldn't this be exact? | |
| # assert dask.compute(*result) == expected |
a = np.random.random(size=30)
b = a[::-1] # this is popmean
and we can't do np.squeeze(b, 0) because it raises:
ValueError: cannot select an axis to squeeze out which has size not equal to one
We need to update this code to be consistent with SciPy
Lines 105 to 121 in 982376e
| @derived_from(scipy.stats) | |
| def ttest_1samp(a, popmean, axis=0, nan_policy="propagate"): | |
| if nan_policy != "propagate": | |
| raise NotImplementedError( | |
| "`nan_policy` other than 'propagate' have not been implemented." | |
| ) | |
| n = a.shape[axis] | |
| df = n - 1 | |
| d = da.mean(a, axis) - popmean | |
| v = da.var(a, axis, ddof=1) | |
| denom = da.sqrt(v / float(n)) | |
| with np.errstate(divide="ignore", invalid="ignore"): | |
| t = da.divide(d, denom) | |
| t, prob = _ttest_finish(df, t) | |
| return delayed(Ttest_1sampResult, nout=2)(t, prob) |
Activity