<commit_before>from copy import deepcopy
from datetime import datetime
from django.utils.translation import ugettext as _
from openbudgets.apps.sheets.models import Template, Sheet, SheetItem
from openbudgets.apps.entities.models import Entity
from openbudgets.apps.international.utilities import translated_fields
from openbudgets.apps.transport.incoming.parsers import register, ParsingError
from openbudgets.apps.transport.incoming.parsers.template import TemplateParser
from openbudgets.apps.transport.incoming.errors import MetaParsingError, NodeNotFoundError


def _rows_filter(obj, row_num=None):
    if obj['has_children']:
        return True
    else:
        if 'budget' in obj:
            try:
                budget = float(obj['budget'])
                if budget > 0:
                    return True
                elif 'actual' in obj:
                    try:
                        actual = float(obj['actual'])
                        return actual > 0
                    except (ValueError, TypeError):
                        pass
            except (ValueError, TypeError):
                if 'actual' in obj:
                    try:
                        actual = float(obj['actual'])
                        return actual > 0
                    except (ValueError, TypeError):
                        pass
        elif 'actual' in obj:
            try:
                actual = float(obj['actual'])
                return actual > 0
            except (ValueError, TypeError):
                pass
        else:
            raise ParsingError(_('Neither actual nor budget columns found.'))

        return False


class SheetParser(TemplateParser):

    container_model = Sheet
    item_model = SheetItem<commit_msg>Simplified _rows_filter based on changes to clean()<commit_after>from copy import deepcopy
from datetime import datetime
from django.utils.translation import ugettext as _
from openbudgets.apps.sheets.models import Template, Sheet, SheetItem
from openbudgets.apps.entities.models import Entity
from openbudgets.apps.international.utilities import translated_fields
from openbudgets.apps.transport.incoming.parsers import register, ParsingError
from openbudgets.apps.transport.incoming.parsers.template import TemplateParser
from openbudgets.apps.transport.incoming.errors import MetaParsingError, NodeNotFoundError


def _rows_filter(obj, row_num=None):
    if obj['has_children']:
        return True
    else:
        if 'budget' in obj:
            if obj['budget'] is not None:
                return True
            else:
                return 'actual' in obj and obj['actual'] is not None

        elif 'actual' in obj:
            return obj['actual'] is not None

        else:
            raise ParsingError(_('Neither actual nor budget columns found.'))


class SheetParser(TemplateParser):

    container_model = Sheet
    item_model = SheetItem
{'fraction_non_alphanumeric': 0.06847900894700619, 'fraction_numerical': 0.0013764624913971094, 'mean_word_length': 2.240802675585284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1365947', 'n_tokens_mistral': 743, 'n_tokens_neox': 698, 'n_words': 220}