<commit_before>import six
from nefertari.utils.dictset import dictset
from nefertari.utils.utils import issequence


class DataProxy(object):
    def __init__(self, data={}):
        self._data = dictset(data)

    def to_dict(self, **kwargs):
        _dict = dictset()
        _keys = kwargs.pop('_keys', [])
        __depth = kwargs.pop('__depth', 10)

        data = dictset(self._data).subset(_keys) if _keys else self._data

        for attr, val in data.items():
            _dict[attr] = val
            if __depth:
                kw = kwargs.copy()
                kw['__depth'] = __depth - 1

                if hasattr(val, 'to_dict'):
                    _dict[attr] = val.to_dict(**kw)
                elif isinstance(val, list):
                    _dict[attr] = to_dicts(val, **kw)

        _dict['_type'] = self.__class__.__name__
        return _dict


def dict2obj(data):
    if not data:
        return data

    _type = str(data.get('_type'))
    top = type(_type, (DataProxy,), {})(data)

    for key, val in top._data.items():
        key = str(key)
        if isinstance(val, dict):
            setattr(top, key, dict2obj(val))<commit_msg>Default __depth to 1 in DataProxy<commit_after>import six
from nefertari.utils.dictset import dictset
from nefertari.utils.utils import issequence


class DataProxy(object):
    def __init__(self, data={}):
        self._data = dictset(data)

    def to_dict(self, **kwargs):
        _dict = dictset()
        _keys = kwargs.pop('_keys', [])
        __depth = kwargs.pop('__depth', 1)

        data = dictset(self._data).subset(_keys) if _keys else self._data

        for attr, val in data.items():
            _dict[attr] = val
            if __depth:
                kw = kwargs.copy()
                kw['__depth'] = __depth - 1

                if hasattr(val, 'to_dict'):
                    _dict[attr] = val.to_dict(**kw)
                elif isinstance(val, list):
                    _dict[attr] = to_dicts(val, **kw)

        _dict['_type'] = self.__class__.__name__
        return _dict


def dict2obj(data):
    if not data:
        return data

    _type = str(data.get('_type'))
    top = type(_type, (DataProxy,), {})(data)

    for key, val in top._data.items():
        key = str(key)
        if isinstance(val, dict):
            setattr(top, key, dict2obj(val))
{'fraction_non_alphanumeric': 0.12718736662398633, 'fraction_numerical': 0.004268032437046522, 'mean_word_length': 2.020618556701031, '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': '320548', 'n_tokens_mistral': 758, 'n_tokens_neox': 721, 'n_words': 180}