import pkgutil

import numpy
import copyreg

import dedupe.variables
import dedupe.variables.base as base
from dedupe.variables.base import MissingDataType
from dedupe.variables.interaction import InteractionType

for _, module, _  in pkgutil.iter_modules(dedupe.variables.__path__, 
                                          'dedupe.variables.') :
    __import__(module)


FIELD_CLASSES = {k : v for k, v in base.allSubclasses(base.FieldType) if k}

class DataModel(object) :

    def __init__(self, fields):

        primary_fields, variables = typifyFields(fields)
        self.primary_fields = primary_fields
        self._derived_start = len(variables)

        variables += interactions(fields, primary_fields)
        variables += missing(variables)

        self._missing_field_indices = missing_field_indices(variables)
        self._interaction_indices = interaction_indices(variables) 

        self._variables = variables

    def __len__(self) :
        return len(self._variables)

    # Changing this from a property to just a normal attribute causes
    # pickling problems, because we are removing static methods from
    # their class context. This could be fixed by defining comparators
    # outside of classes in fieldclasses
    @property 
    def _field_comparators(self) :
        start = 0
        stop = 0
        comparators = []
        for field in self.primary_fields :
            stop = start + len(field) 
            comparators.append((field.field, field.comparator, start, stop))