Check whether the timeseries values match the aggregation
    of sub-categories

    Parameters
    ----------
    df: IamDataFrame instance
    args: see IamDataFrame.check_aggregate() for details
    kwargs: passed to `df.filter()`
966646
def check_aggregate(df, variable, components=None, exclude_on_fail=False,
                    multiplier=1, **kwargs):
    
    fdf = df.filter(**kwargs)
    if len(fdf.data) > 0:
        vdf = fdf.check_aggregate(variable=variable, components=components,
                                  exclude_on_fail=exclude_on_fail,
                                  multiplier=multiplier)
        df.meta['exclude'] |= fdf.meta['exclude']  # update if any excluded
        return vdf
281759
def drop_duplicates_agg(df,colsgroupby,cols2aggf,test=False):
    
    if test:
        print(df.shape)
        print(df.drop_duplicates(subset=colsgroupby).shape)
    #ddup aggregated
    dfdupagg=df.loc[(df.duplicated(subset=colsgroupby,keep=False)),:].groupby(colsgroupby).agg(cols2aggf)
    #drop duplicates all
    df_=df.drop_duplicates(subset=colsgroupby,keep=False)
    if test:
        print(df_.shape)
    #append ddup aggregated
    dfout=df_.append(dfdupagg,sort=True)
    if test:
        print(dfout.shape)
    return dfout
1336439
def _identify(self, dataframe):
        
        path = Path(self.vert)
        idx = path.contains_points(dataframe.filter(self.channels))

        if self.region == 'out':
            idx = ~idx

        return idx
72269
def trend(self, **kwargs):
        ''''''
        return DataFrame({ name: series.trend(**kwargs) \
            for name, series in self.groups.iteritems() })
640250
def get_aggs(self):
        

        res = self.fetch_aggregation_results()
        if 'aggregations' in res and 'values' in res['aggregations'][str(self.parent_agg_counter - 1)]:
            try:
                agg = res['aggregations'][str(self.parent_agg_counter - 1)]['values']["50.0"]
                if agg == 'NaN':
                    # ES returns NaN. Convert to None for matplotlib graph
                    agg = None
            except Exception as e:
                raise RuntimeError("Multivalue aggregation result not supported")

        elif 'aggregations' in res and 'value' in res['aggregations'][str(self.parent_agg_counter - 1)]:
            agg = res['aggregations'][str(self.parent_agg_counter - 1)]['value']

        else:
            agg = res['hits']['total']

        return agg
330824
def is_series(obj):
    
    try:
        # This is the best method of type checking
        from pandas import Series
        return isinstance(obj, Series)
    except ImportError:
        # Pandas is not a dependency, so this is scary
        return obj.__class__.__name__ == "Series"
438655
def _bool_agg(self, val_test, skipna):
        

        def objs_to_bool(vals: np.ndarray) -> Tuple[np.ndarray, Type]:
            if is_object_dtype(vals):
                vals = np.array([bool(x) for x in vals])
            else:
                vals = vals.astype(np.bool)

            return vals.view(np.uint8), np.bool

        def result_to_bool(result: np.ndarray, inference: Type) -> np.ndarray:
            return result.astype(inference, copy=False)

        return self._get_cythonized_result('group_any_all', self.grouper,
                                           aggregate=True,
                                           cython_dtype=np.uint8,
                                           needs_values=True,
                                           needs_mask=True,
                                           pre_processing=objs_to_bool,
                                           post_processing=result_to_bool,
                                           val_test=val_test, skipna=skipna)
1036658
def validate_a_time_filter(self, value):
        
        if value:
            try:
                utils.parse_datetime_range(value)
            except Exception as e:
                raise serializers.ValidationError(e.message)

        return value
871128
def aggregate(self, *args, **kwargs):
        
        if self.query.distinct_fields:
            raise NotImplementedError("aggregate() + distinct(fields) not implemented.")
        for arg in args:
            # The default_alias property may raise a TypeError, so we use
            # a try/except construct rather than hasattr in order to remain
            # consistent between PY2 and PY3 (hasattr would swallow
            # the TypeError on PY2).
            try:
                arg.default_alias
            except (AttributeError, TypeError):
                raise TypeError("Complex aggregates require an alias")
            kwargs[arg.default_alias] = arg

        if django.VERSION < (2, 0):
            query = self.query.clone(CTEAggregateQuery)
        else:
            query = self.query.chain(CTEAggregateQuery)
        for (alias, aggregate_expr) in kwargs.items():
            query.add_annotation(aggregate_expr, alias, is_summary=True)
            if not query.annotations[alias].contains_aggregate:
                raise TypeError("%s is not an aggregate expression" % alias)
        return query.get_aggregation(self.db, kwargs.keys())
167889
def rolling(self, *args, **kwargs):
        
        from pandas.core.window import RollingGroupby
        return RollingGroupby(self, *args, **kwargs)
801076
public boolean checkTimeframeArg(String timeframe) {
        if (Pattern.compile("\\d*(d|h)", Pattern.CASE_INSENSITIVE).matcher(timeframe).matches()) {
            return true;
        } else {
            return false;
        }
    }
212087
def process_one(df, *keys, columns=['key', 'agent_id'], values='value',
                fill=True, index=['t_step',],
                aggfunc='first', **kwargs):
    '''
    
    '''
    if df is None:
        return df
    if keys:
        df = df[df['key'].isin(keys)]

    df = df.pivot_table(values=values, index=index, columns=columns,
                        aggfunc=aggfunc, **kwargs)
    if fill:
        df = fillna(df)
    return df
1083096
def _aggregate(df, by):
    """"""
    by = [by] if isstr(by) else by
    cols = [c for c in list(df.columns) if c not in ['value'] + by]
    return df.groupby(cols).sum()['value']
463310
def _should_process(self, data_dict, collect_aggregates_only):
        
        if collect_aggregates_only:
            if self._is_aggregate(data_dict):
                return True
            return False
        elif data_dict['svname'] == Services.BACKEND:
            return False
        return True
979448
def calc_stats(prices):
    
    if isinstance(prices, pd.Series):
        return PerformanceStats(prices)
    elif isinstance(prices, pd.DataFrame):
        return GroupStats(*[prices[x] for x in prices.columns])
    else:
        raise NotImplementedError('Unsupported type')
334457
def is_known_scalar(value):
    
    def _is_datetime_or_timedelta(value):
        # Using pandas.Series helps catch python, numpy and pandas
        # versions of these types
        return pd.Series(value).dtype.kind in ('M', 'm')

    return not np.iterable(value) and (isinstance(value, numbers.Number) or
                                       _is_datetime_or_timedelta(value))
282922
def verify_all(df, check, *args, **kwargs):
    
    result = check(df, *args, **kwargs)
    try:
        assert np.all(result)
    except AssertionError as e:
        msg = "{} not true for all".format(check.__name__)
        e.args = (msg, df[~result])
        raise
    return df