ENH: add dtype arg to stats.mstats.gmean and stats.mstats.hmean #3302

Closed
wants to merge 1 commit into
from

5 participants

@andreas-h

fixes #3196

@coveralls

Coverage Status

Coverage remained the same when pulling 26db2b7 on andreas-h:gh3196 into 1f9f36d on scipy:master.

@pv pv added the PR label Feb 19, 2014
@rgommers rgommers commented on an outdated diff Feb 23, 2014
scipy/stats/tests/test_mstats_basic.py
@@ -58,6 +58,11 @@ def test_1D(self):
desired1 = mstats.gmean(a,axis=-1)
assert_almost_equal(actual, desired1, decimal=14)
+ actualdt = mstats.gmean(a, dtype=np.float128)
+ desireddt = np.power(1*2*3,1./3.).astype(np.float128)
@rgommers
SciPy member
rgommers added a line comment Feb 23, 2014

Can you add some underscores? actual_dt and desider_dt is more readable. also in the test for hmean.

@rgommers
SciPy member
rgommers added a line comment Feb 23, 2014

and some spaces in the power call for PEP8 compat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rgommers rgommers commented on an outdated diff Feb 23, 2014
scipy/stats/mstats_basic.py
a, axis = _chk_asarray(a, axis)
if isinstance(a, MaskedArray):
size = a.count(axis)
else:
size = a.shape[axis]
- return size / (1.0/a).sum(axis)
+ if dtype:
+ a_ = ma.asarray(a, dtype=dtype)
@rgommers
SciPy member
rgommers added a line comment Feb 23, 2014

The underscore isn't needed, use a = instead of a_ =.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rgommers
SciPy member

Actually, stats.gmean and stats.hmean support masked arrays. So probably the implementations in mstats_basic.py can simply be deleted and the stats version added to the mstats namespace. Tests could be kept though.

@andreas-h
@rgommers
SciPy member

Not needed I think, it's only kept in that namespace for backwards compat.

@andreas-h andreas-h MAINT: use implementation from scipy.stats in scipy.stats.mstats for …
…gmean and hmean

TST: test correct dtype handling in masked_array case in scipy.stats.gmean and hmean

fixes #3196
ffbf26e
@andreas-h

Done.

@coveralls

Coverage Status

Coverage remained the same when pulling ffbf26e on andreas-h:gh3196 into 0da153e on scipy:master.

@rgommers rgommers added this to the 0.14.0 milestone Feb 24, 2014
@rgommers rgommers added a commit that referenced this pull request Feb 24, 2014
@rgommers rgommers Merge branch 'pr/3302' into master.
Review at #3302
a8abcfb
@rgommers
SciPy member

OK merged in a8abcfb. I fixed two issues: use assert_ instead of assert and use float96 instead of float128 (the latter isn't present in numpy 1.5.1).

@rgommers rgommers closed this Feb 24, 2014
@rgommers
SciPy member

Thanks Andreas.

@andreas-h andreas-h deleted the andreas-h:gh3196 branch Feb 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment