#362 Sample operation initial work

Initial version of Sample() operation implemented and tested for numpy and pandas.
Sample() should randomly select some items from a given datasource and return them.
For numpy and pandas, the returned data are new arrays or dataframes or series.

I don't think that the data would ever be converted to np.ndarray.  Using
the .dispatch() method we trick the compute_one function to use the numpy
implementation a non-numpy type.  This function doesn't ever appear to
convert the data to a numpy type.  It only requires that len and getitem
works, which should be true for all of numpy, pandas, tables, bcolz.


On Fri, Sep 5, 2014 at 3:48 PM, nevermindewe <notifications@github.com>
wrote:

> In blaze/compute/pytables.py:
>
> > @@ -110,3 +110,29 @@ def compute_one(s, t, **kwargs):
> >      if s.ascending:
> >          return result
> >      return result[::-1]
> > +
> > +@dispatch(Sample, tb.Table)
> > +def compute_one(expr, data, **kwargs):
> > +    """
> > +    @param expr - The TableExpr that we are calculating over
> > +    @param data - The numpy ndarray we are sampling from
> > +    @param replace (Optional) - Tells whether to sample with or without replacement. The default is False.
> > +
> > +    Each time compute(sample(), ndarray) is called, a new, different ndarray should be returned
> > +    """
>
> @mrocklin <https://github.com/mrocklin> - Do I understand correctly that
> the input data would then have to be converted to/from np.ndarray upon
> entry and exit?
> Something like the following?
>
> f = compute_one.dispatch(Sample, np.ndarray)return into(originating_type, f(expr, into(np.ndarray, data), **kwargs)), **kwargs)
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/ContinuumIO/blaze/pull/591/files#r17202602>.
>