Example #1
0
    def _cython_agg_general(self, how):
        label_list = [ping.labels for ping in self.groupings]
        shape = self._group_shape

        # TODO: address inefficiencies, like duplicating effort (should
        # aggregate all the columns at once?)

        output = {}
        cannot_agg = []
        for name, obj in self._iterate_slices():
            if issubclass(obj.dtype.type, (np.number, np.bool_)):
                if obj.dtype != np.float64:
                    obj = obj.astype('f8')
            else:
                cannot_agg.append(name)
                continue

            result, counts =  lib.group_aggregate(obj, label_list,
                                                  shape, how=how)
            result = result.ravel()
            mask = counts.ravel() > 0
            output[name] = result[mask]

        if len(output) == 0:
            raise GroupByError('No numeric types to aggregate')

        return self._wrap_aggregated_output(output, mask)
Example #2
0
    def _cython_agg_general(self, how):
        label_list = [ping.labels for ping in self.groupings]
        shape = self._group_shape

        # TODO: address inefficiencies, like duplicating effort (should
        # aggregate all the columns at once?)

        output = {}
        cannot_agg = []
        for name, obj in self._iterate_slices():
            try:
                obj = np.asarray(obj, dtype=float)
            except ValueError:
                cannot_agg.append(name)
                continue

            result, counts =  _tseries.group_aggregate(obj, label_list,
                                                       shape, how=how)
            result = result.ravel()
            mask = counts.ravel() > 0
            output[name] = result[mask]

        return self._wrap_aggregated_output(output, mask)