Skip to content

[UPSTREAM] test_stats.py::test_two[ttest_1samp-kwargs2] failing #9499

Open

Description

@ncclementi

Looks like Scipy modify what is accepted as popmean in scipy.stats.ttest_1samp

scipy=1.9.1

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.

dev

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

@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

dask/dask/array/stats.py

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

  1. added
    needs triage
    on Sep 15, 2022
  2. added
    tests
    and removed
    needs triage
    on Sep 15, 2022
  3. added
    needs attention
    on Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs attentiontestsupstream

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions