Skip to content

Commit

Permalink
Merge d4accde into 1e6b7c6
Browse files Browse the repository at this point in the history
  • Loading branch information
esmucler committed Aug 26, 2020
2 parents 1e6b7c6 + d4accde commit 99ce588
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions statsmodels/robust/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ def mad(a, c=Gaussian.ppf(3/4.), axis=0, center=np.median):
"""
a = array_like(a, 'a', ndim=None)
c = float_like(c, 'c')
if callable(center) and a.size:
center = np.apply_over_axes(center, a, axis)
if a.size:
if callable(center):
center = np.apply_over_axes(center, a, axis)
else:
center = float_like(center, 'center')
else:
center = 0.0

Expand Down
7 changes: 7 additions & 0 deletions statsmodels/robust/tests/test_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
from numpy.random import standard_normal
from numpy.testing import assert_almost_equal, assert_equal
from scipy.stats import norm as Gaussian
import pytest
# Example from Section 5.5, Venables & Ripley (2002)

Expand Down Expand Up @@ -81,6 +82,12 @@ def test_mad_empty(self):
def test_mad_center(self):
n = scale.mad(self.X, center=0)
assert_equal(n.shape, (10,))
with pytest.raises(TypeError):
scale.mad(self.X, center=None)
assert_almost_equal(scale.mad(self.X, center=1),
np.median(np.abs(self.X - 1),
axis=0)/Gaussian.ppf(3/4.),
DECIMAL)


class TestMadAxes(object):
Expand Down

0 comments on commit 99ce588

Please sign in to comment.