Skip to content

Commit

Permalink
MAINT: stats: avoid (a spurious) division-by-zero in skew
Browse files Browse the repository at this point in the history
Use _lazywhere instead of ``np.where(m2==0, 0, m3/m2**1.5)``
  • Loading branch information
ev-br committed Apr 14, 2015
1 parent 4f65e8e commit d338161
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scipy/stats/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
import numpy as np
from . import futil
from . import distributions
from ._distn_infrastructure import _lazywhere

from ._rank import rankdata, tiecorrect

Expand Down Expand Up @@ -1042,7 +1043,9 @@ def skew(a, axis=0, bias=True):
m2 = moment(a, 2, axis)
m3 = moment(a, 3, axis)
zero = (m2 == 0)
vals = np.where(zero, 0, m3 / m2**1.5)
vals = _lazywhere(~zero, (m2, m3),
lambda m2, m3: m3 / m2**1.5,
0.)
if not bias:
can_correct = (n > 2) & (m2 > 0)
if can_correct.any():
Expand Down

0 comments on commit d338161

Please sign in to comment.