<commit_before>import pickle

from pathlib import Path
from time import process_time

from regulus.data.data import Data
from regulus.topo import msc, Regulus
from regulus.measures import *
from regulus.models import *


def load(filename):
    path = Path(filename).with_suffix('.regulus')
    with open(path, 'rb') as f:
        t = pickle.load(f)
        if isinstance(t, Regulus):
            t.filename = path
            return t
        raise Exception('file %1 is not a Regulus file'.format(filename))


def save(regulus, filename=None):
    if filename is None and regulus.filename is None:
        raise(Exception("Filename must be provide when the Regulus object doesn't have a default filename"))

    if filename is None:
        filename = regulus.filename
    path = Path(filename).with_suffix('.regulus')
    if regulus.filename is None:
        regulus.filename = path

    with open(path, 'wb') as f:
        pickle.dump(regulus, f)


def add_defaults(regulus):
    regulus.add_attr(linear_model, name='linear')
    regulus.add_attr(fitness)
    regulus.add_attr(relative_fitness)
    regulus.add_attr(stepwise_fitness)

    regulus.tree.add_attr(parent_fitness)
    regulus.tree.add_attr(child_fitness)
    regulus.tree.add_attr(node_size, name='size')
    regulus.tree.add_attr(node_relative_size, name='rel_size')
    regulus.tree.add_attr(node_span, name='span')


def from_csv(filename, **kwargs):
    t_start = process_time()
    path = Path(filename)
    ndims = kwargs.pop('ndims', None)
    pts = Data.read_csv(path.with_suffix('.csv'), ndims=ndims)
    t_read = process_time()

    pts.normalize()
    regulus = msc(pts, **kwargs)
    t_msc = process_time()<commit_msg>add min and max default attributes<commit_after>import pickle

from pathlib import Path
from time import process_time

from regulus.data.data import Data
from regulus.topo import msc, Regulus
from regulus.measures import *
from regulus.models import *


def load(filename):
    path = Path(filename).with_suffix('.regulus')
    with open(path, 'rb') as f:
        t = pickle.load(f)
        if isinstance(t, Regulus):
            t.filename = path
            return t
        raise Exception('file %1 is not a Regulus file'.format(filename))


def save(regulus, filename=None):
    if filename is None and regulus.filename is None:
        raise(Exception("Filename must be provide when the Regulus object doesn't have a default filename"))

    if filename is None:
        filename = regulus.filename
    path = Path(filename).with_suffix('.regulus')
    if regulus.filename is None:
        regulus.filename = path

    with open(path, 'wb') as f:
        pickle.dump(regulus, f)


def add_defaults(regulus):
    regulus.add_attr(linear_model, name='linear')
    regulus.add_attr(fitness)
    regulus.add_attr(relative_fitness)
    regulus.add_attr(stepwise_fitness)
    regulus.add_attr(node_min, name='min')
    regulus.add_attr(node_max, name='max')

    regulus.tree.add_attr(parent_fitness)
    regulus.tree.add_attr(child_fitness)
    regulus.tree.add_attr(node_size, name='size')
    regulus.tree.add_attr(node_relative_size, name='rel_size')
    regulus.tree.add_attr(node_span, name='span')


def from_csv(filename, **kwargs):
    t_start = process_time()
    path = Path(filename)
    ndims = kwargs.pop('ndims', None)
    pts = Data.read_csv(path.with_suffix('.csv'), ndims=ndims)
    t_read = process_time()

    pts.normalize()
    regulus = msc(pts, **kwargs)
    t_msc = process_time()
{'fraction_non_alphanumeric': 0.10911168237646386, 'fraction_numerical': 0.0005712653527563553, 'mean_word_length': 3.5837696335078535, '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': '5282739', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1127, 'n_words': 272}