<commit_before>import json
from noat       import NOAT
from datetime   import date, datetime

from .fields import *

import copy


def _get_field_type_for(name, value):
    """
    Private: return the field for the specified value, either based on the
             type of the value, or based on the suffix of the name. The
             suffixes are a soft convention. Values that do not validate to
             that type are treated like their actual value type. eg fields
             ending in '_date' are checked against the 

    name    - the string name of the field
    value   - the * value of the field

    Returns a subclass of BaseField.
    """

    if name.endswith('_date'):
        try:
            DateTimeField().set(value).validate()
        except ValueError:
            pass
        else:
            return DateTimeField

    if name.endswith('_content'):
        try:
            ContentReferenceField().set(value).validate()
        except (ValueError, TypeError, KeyError):
            pass
        else:
            return ContentReferenceField

        try:
            ContainerContentField().set(value).validate()
        except (ValueError, TypeError, KeyError):
            pass
        else:
            return ContainerContentField

    field_map = (
        (bool       , BooleanField),
        (basestring , StringField),
        (dict       , DictField),
        (int        , IntField),
        (float      , FloatField),
        (list       , ListField),
        (datetime   , DateTimeField),
        (date       , DateTimeField),
    )
    for python_type, field_type in field_map:
        if isinstance(value, python_type):
            return field_type

    # Default to StringField for anything else - in case one of the values is
    # None, for example.
    return StringField 


<commit_msg>Need to catch AttributeError validation failures<commit_after>import json
from noat       import NOAT
from datetime   import date, datetime

from .fields import *

import copy


def _get_field_type_for(name, value):
    """
    Private: return the field for the specified value, either based on the
             type of the value, or based on the suffix of the name. The
             suffixes are a soft convention. Values that do not validate to
             that type are treated like their actual value type. eg fields
             ending in '_date' are checked against the 

    name    - the string name of the field
    value   - the * value of the field

    Returns a subclass of BaseField.
    """

    if name.endswith('_date'):
        try:
            DateTimeField().set(value).validate()
        except ValueError:
            pass
        else:
            return DateTimeField

    if name.endswith('_content'):
        try:
            ContentReferenceField().set(value).validate()
        except (ValueError, TypeError, KeyError, AttributeError):
            pass
        else:
            return ContentReferenceField

        try:
            ContainerContentField().set(value).validate()
        except (ValueError, TypeError, KeyError, AttributeError):
            pass
        else:
            return ContainerContentField

    field_map = (
        (bool       , BooleanField),
        (basestring , StringField),
        (dict       , DictField),
        (int        , IntField),
        (float      , FloatField),
        (list       , ListField),
        (datetime   , DateTimeField),
        (date       , DateTimeField),
    )
    for python_type, field_type in field_map:
        if isinstance(value, python_type):
            return field_type

    # Default to StringField for anything else - in case one of the values is
    # None, for example.
    return StringField 



{'fraction_non_alphanumeric': 0.06835781041388518, 'fraction_numerical': 0.0, 'mean_word_length': 1.8948995363214838, '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': '2800523', 'n_tokens_mistral': 943, 'n_tokens_neox': 914, 'n_words': 343}