I just checked:
in scipy 0.9 scipy.stats.scoreatpercentile doesn't contain a cast to
array, np.asarray, that's a bug in scipy.stats.
>>> type(weeklymax)
<class 'pandas.core.series.TimeSeries'>
>>> type(np.sort(weeklymax))
<class 'pandas.core.series.TimeSeries'>
>>> type(np.sort(np.ma.arange(5)))
<class 'numpy.ma.core.MaskedArray'>
I guess, before the assumption was that np.sort(some subclass) returns
an ndarray, but obviously np.sort doesn't change the type of a array
subtype.
If you are on numpy >= 1.6, there is a similar new function in numpy
that should work. (Skipper used it, but I'm on numpy 1.5)
Josef
although, it still works on TimeSeries
>>> type(weeklymax)
<class 'pandas.core.series.TimeSeries'>
>>> stats.scoreatpercentile(weeklymax, per=50)
0.020191766815031542
Josef
Please file the ticket, I haven't done it yet.
adding np.asarray is a bug fix,
but there are also enhancement that could be done, Skipper and I
worked on it in statsmodels, but it still needs to be reviewed and I
think the options are not settled yet.
>
> btw, I was a bit surprised that scipy.stats.scoreatpercentile's per
> argument actually expects the percent value [0,100] instead of a value
> [0,1]. Maybe it would be nice to add this to the docs.
I was surprised also, but since the function uses percentile in the
name and in the documentation for the per argument, it shouldn't be
too surprising, unless you expect a `quantile` function as I did
initially.
The example in the docstring also uses 50 not 0.5.
Josef
>
> Cheers,
> Andreas.
forgot to add:
Wes,
Does np.asarray on a pandas object make a copy or a view?
Josef
It returns a view.
BTW you should use the quantile function on Series or DataFrame, so you can do:
grouped_by_lat['local time'].quantile(0.05)
this just uses scoreatpercentile under the hood but much more concise and no bug
But if you hide/avoid the bug, we don't get the report .)
Thanks,
Josef
I think scoreatpercentile also takes a number between 0 and 100 which
has always struck me as a little odd (or at least inconsistent with
other quantile functions).