# [Scipy-tickets] [SciPy] #1291: stats.discrete distributions hypergeom.sf exception

SciPy Trac scipy-tickets@scipy....
Fri Oct 22 12:09:24 CDT 2010

```#1291: stats.discrete distributions hypergeom.sf exception
-------------------------+--------------------------------------------------
Reporter:  josefpktd    |       Owner:  somebody
Type:  defect       |      Status:  needs_review
Priority:  normal       |   Milestone:  0.9.0
Component:  scipy.stats  |     Version:  0.7.0
Keywords:               |
-------------------------+--------------------------------------------------

Comment(by jledoux):

Yup you are right; my quick fix broke it.  Adding your if any(cond): seems
to work.

{{{
def sf(self,k,*args,**kwds):
"""
Survival function (1-cdf) at k of the given RV

Parameters
----------
k : array-like
quantiles
arg1, arg2, arg3,... : array-like
The shape parameter(s) for the distribution (see docstring of
the
loc : array-like, optional
location parameter (default=0)

Returns
-------
sf : array-like
Survival function evaluated at k

"""
loc= kwds.get('loc')
args, loc = self._fix_loc(args, loc)
k,loc = map(arr,(k,loc))
args = tuple(map(arr,args))
k = arr(k-loc)
cond0 = self._argcheck(*args)
cond1 = (k >= self.a) & (k <= self.b)
cond2 = (k < self.a) & cond0
cond = cond0 & cond1
output = zeros(shape(cond),'d')
place(output,cond2,1.0)
goodargs = argsreduce(cond, *((k,)+args))

if any(cond):
place(output,cond,self._sf(*goodargs))

if output.ndim == 0:
return output[()]

return output
}}}

Tested well for negative values, values where k > n (cases when it used to
fail, if hypergeom hadn't been used prior), and values where sf isn't zero
or 1 and it works well.

--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1291#comment:6>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
```