<commit_before>from celery.task import task

from bamboo.core.calculator import Calculator
from bamboo.core.frame import DATASET_ID
from bamboo.lib.async import call_async
from bamboo.lib.exceptions import ArgumentError
from bamboo.lib.schema_builder import make_unique
from bamboo.models.abstract_model import AbstractModel


class DependencyError(Exception):
    pass


@task
def delete_task(calculation, dataset, slug):
    """Background task to delete `calculation` and columns in its dataset.

    Args:

    :param calculation: Calculation to delete.
    :param dataset: Dataset for this calculation.

    """
    dframe = dataset.dframe(keep_parent_ids=True)
    del dframe[slug]
    dataset.replace_observations(dframe, overwrite=True)
    calculation.remove_dependencies()

    super(calculation.__class__, calculation).delete({
        DATASET_ID: calculation.dataset_id,
        calculation.NAME: calculation.name
    })


@task(max_retries=10)
def calculate_task(calculation, dataset):
    """Background task to run a calculation.

    :param calculation: Calculation to run.
    :param dataset: Dataset to run calculation on.
    """
    # block until other calculations for this dataset are finished
    calculation.restart_if_has_pending(dataset)
    dataset.clear_summary_stats()

    calculator = Calculator(dataset)
    calculator.calculate_column(calculation.formula, calculation.name,
                                calculation.group)
    calculation.add_dependencies(dataset, calculator.dependent_columns())

    if calculation.group is not None:
        dataset.reload()<commit_msg>handle not aggreagtion<commit_after>from celery.task import task

from bamboo.core.calculator import Calculator
from bamboo.core.frame import DATASET_ID
from bamboo.lib.async import call_async
from bamboo.lib.exceptions import ArgumentError
from bamboo.lib.schema_builder import make_unique
from bamboo.models.abstract_model import AbstractModel


class DependencyError(Exception):
    pass


@task
def delete_task(calculation, dataset, slug):
    """Background task to delete `calculation` and columns in its dataset.

    Args:

    :param calculation: Calculation to delete.
    :param dataset: Dataset for this calculation.

    """
    dframe = dataset.dframe(keep_parent_ids=True)
    del dframe[slug]
    dataset.replace_observations(dframe, overwrite=True)
    calculation.remove_dependencies()

    super(calculation.__class__, calculation).delete({
        DATASET_ID: calculation.dataset_id,
        calculation.NAME: calculation.name
    })


@task(max_retries=10)
def calculate_task(calculation, dataset):
    """Background task to run a calculation.

    :param calculation: Calculation to run.
    :param dataset: Dataset to run calculation on.
    """
    # block until other calculations for this dataset are finished
    calculation.restart_if_has_pending(dataset)
    dataset.clear_summary_stats()

    calculator = Calculator(dataset)
    calculator.calculate_column(calculation.formula, calculation.name,
                                calculation.group)
    calculation.add_dependencies(dataset, calculator.dependent_columns())

    if calculation.aggregation is not None:
        dataset.reload()
{'fraction_non_alphanumeric': 0.07565891472868216, 'fraction_numerical': 0.00124031007751938, 'mean_word_length': 4.001550387596899, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3801257', 'n_tokens_mistral': 908, 'n_tokens_neox': 850, 'n_words': 235}