# Path: wallace/data_type_classification.py
# class DataTypeClassification(object):
#     VALID_DATE_FORMATS = [
#             "%m/%d/%y",
#             "%m-%d-%y",
#             "%d/%m/%y",
#             "%d-%m-%y",
#             "%m/%d/%Y",
#             "%m-%d-%Y",
#             "%d/%m/%Y",
#             "%d-%m-%Y"
#             ]
# 
#     @classmethod
#     def is_integer(klass, obj):
#         try:
#             int(obj)
#             return True
#         except ValueError:
#             return False
# 
#     @classmethod
#     def is_float(klass, obj):
#         try:
#             float(obj)
#             return True
#         except ValueError:
#             return False
# 
#     @classmethod
#     def is_boolean(klass, obj):
#         lowercased = obj.strip().lower()
#         return lowercased in ["true", "t", "false", "f"]
# 
#     @classmethod
#     def is_missing_data(klass, obj):
#         if obj == None:
#             return True
#         if isinstance(obj, str):
#             lowercased = obj.strip().lower()
#             return lowercased in ["nan", "null", "na", ""]
#         else:
#             return False
# 
#     @classmethod
#     def is_date(klass, entry):
#         try:
#             klass.get_date(entry)
#             return True
#         except ValueError:
#             return False
# 
#     @classmethod
#     def get_date(klass, entry):
#         for date_format in klass.VALID_DATE_FORMATS:
#             try:
#                 return datetime.strptime(entry, date_format)
#             except ValueError:
#                 pass
#         raise ValueError("Unable to convert entry into a datetime object.")
# 
#     @classmethod
#     def classify(klass, entry):
#         if klass.is_integer(entry):
#             return DataType("integer")
#         elif klass.is_float(entry):
#             return DataType("float")
#         elif klass.is_boolean(entry):
#             return DataType("boolean")
#         elif klass.is_date(entry):
#             return DataType("date")
#         else:
#             return DataType("string")
# 
#     @classmethod
#     def classify_row(klass, row):
#         return [klass.classify(entry) for entry in row]
# 
#     @classmethod
#     def classify_data_matrix(klass, data_matrix):
#         num_columns = len(data_matrix[0])
#         classifications = [None for i in xrange(num_columns)]
#         row = 0
#         while (None in classifications):
#             if row == len(data_matrix):
#                 raise ValueError("Unable to classify data matrix. Too many missing data points.")
# 
#             for col in xrange(num_columns):
#                 entry = data_matrix[row][col]
#                 if classifications[col] == None and not klass.is_missing_data(entry):
#                     classifications[col] = klass.classify(entry)
#             row += 1
# 
#         return classifications
# 
# Path: wallace/data_type.py
# class DataType(object):
#     VALID_DATA_TYPES = [
#             "integer",
#             "float",
#             "boolean",
#             "date",
#             "string"
#         ]
# 
# 
#     def __init__(self, data_type, categories=None):
#         self.categories = categories
#         if data_type in self.VALID_DATA_TYPES:
#             self.data_type = data_type
#         else:
#             raise ValueError("Data type '%s' is not a valid data type." % data_type)
# 
#     def in_categories(self, data_value):
#         if self.data_type != "string":
#             raise ValueError("Categories are only valid for 'string' data types.")
# 
#         return (data_value in self.categories)
# 
#     def is_equal(self, data_type):
#         return self.data_type == data_type
# 
#     def __str__(self):
#         return self.data_type
# 
#     def __repr__(self):
#         return self.__str__()


import random
from wallace.data_type_classification import DataTypeClassification
from wallace.data_type import DataType
        random.shuffle(shuffled)

        for i in xrange(num_partitions):
            test_start = i * rows_per_partition
            if i < num_partitions - 1:
                test_end = (i+1) * rows_per_partition
            else:
                test_end = self.num_rows

            training_dataset = Dataset(shuffled[:test_start] + shuffled[test_end:], self.headers, self.data_types)
            test_dataset = Dataset(shuffled[test_start:test_end], self.headers, self.data_types)
            yield (training_dataset, test_dataset)

    def _initialize_data_types(self, data_types):
        if data_types == None:
            resulting_types = DataTypeClassification.classify_data_matrix(self.data_matrix)
        else:
            if len(data_types) != self.num_cols:
                raise ValueError("The data_types lists must be the same length as the number of columns in the dataset.")

            resulting_types = []
            for data_type in data_types:
                if isinstance(data_type, str):
                    resulting_types.append(DataType(data_type))
                else:
                    resulting_types.append(data_type)

        # Get categories for the string data types.
        for i in xrange(len(resulting_types)):
            if resulting_types[i].is_equal("string") and resulting_types[i].categories == None:

# Path: wallace/data_type_classification.py
# class DataTypeClassification(object):
#     VALID_DATE_FORMATS = [
#             "%m/%d/%y",
#             "%m-%d-%y",
#             "%d/%m/%y",
#             "%d-%m-%y",
#             "%m/%d/%Y",
#             "%m-%d-%Y",
#             "%d/%m/%Y",
#             "%d-%m-%Y"
#             ]
# 
#     @classmethod
#     def is_integer(klass, obj):
#         try:
#             int(obj)
#             return True
#         except ValueError:
#             return False
# 
#     @classmethod
#     def is_float(klass, obj):
#         try:
#             float(obj)
#             return True
#         except ValueError:
#             return False
# 
#     @classmethod
#     def is_boolean(klass, obj):
#         lowercased = obj.strip().lower()
#         return lowercased in ["true", "t", "false", "f"]
# 
#     @classmethod
#     def is_missing_data(klass, obj):
#         if obj == None:
#             return True
#         if isinstance(obj, str):
#             lowercased = obj.strip().lower()
#             return lowercased in ["nan", "null", "na", ""]
#         else:
#             return False
# 
#     @classmethod
#     def is_date(klass, entry):
#         try:
#             klass.get_date(entry)
#             return True
#         except ValueError:
#             return False
# 
#     @classmethod
#     def get_date(klass, entry):
#         for date_format in klass.VALID_DATE_FORMATS:
#             try:
#                 return datetime.strptime(entry, date_format)
#             except ValueError:
#                 pass
#         raise ValueError("Unable to convert entry into a datetime object.")
# 
#     @classmethod
#     def classify(klass, entry):
#         if klass.is_integer(entry):
#             return DataType("integer")
#         elif klass.is_float(entry):
#             return DataType("float")
#         elif klass.is_boolean(entry):
#             return DataType("boolean")
#         elif klass.is_date(entry):
#             return DataType("date")
#         else:
#             return DataType("string")
# 
#     @classmethod
#     def classify_row(klass, row):
#         return [klass.classify(entry) for entry in row]
# 
#     @classmethod
#     def classify_data_matrix(klass, data_matrix):
#         num_columns = len(data_matrix[0])
#         classifications = [None for i in xrange(num_columns)]
#         row = 0
#         while (None in classifications):
#             if row == len(data_matrix):
#                 raise ValueError("Unable to classify data matrix. Too many missing data points.")
# 
#             for col in xrange(num_columns):
#                 entry = data_matrix[row][col]
#                 if classifications[col] == None and not klass.is_missing_data(entry):
#                     classifications[col] = klass.classify(entry)
#             row += 1
# 
#         return classifications
# 
# Path: wallace/data_type.py
# class DataType(object):
#     VALID_DATA_TYPES = [
#             "integer",
#             "float",
#             "boolean",
#             "date",
#             "string"
#         ]
# 
# 
#     def __init__(self, data_type, categories=None):
#         self.categories = categories
#         if data_type in self.VALID_DATA_TYPES:
#             self.data_type = data_type
#         else:
#             raise ValueError("Data type '%s' is not a valid data type." % data_type)
# 
#     def in_categories(self, data_value):
#         if self.data_type != "string":
#             raise ValueError("Categories are only valid for 'string' data types.")
# 
#         return (data_value in self.categories)
# 
#     def is_equal(self, data_type):
#         return self.data_type == data_type
# 
#     def __str__(self):
#         return self.data_type
# 
#     def __repr__(self):
#         return self.__str__()


# Path: wallace/dataset.py
import random
from wallace.data_type_classification import DataTypeClassification
from wallace.data_type import DataType

        random.shuffle(shuffled)

        for i in xrange(num_partitions):
            test_start = i * rows_per_partition
            if i < num_partitions - 1:
                test_end = (i+1) * rows_per_partition
            else:
                test_end = self.num_rows

            training_dataset = Dataset(shuffled[:test_start] + shuffled[test_end:], self.headers, self.data_types)
            test_dataset = Dataset(shuffled[test_start:test_end], self.headers, self.data_types)
            yield (training_dataset, test_dataset)

    def _initialize_data_types(self, data_types):
        if data_types == None:
            resulting_types = DataTypeClassification.classify_data_matrix(self.data_matrix)
        else:
            if len(data_types) != self.num_cols:
                raise ValueError("The data_types lists must be the same length as the number of columns in the dataset.")

            resulting_types = []
            for data_type in data_types:
                if isinstance(data_type, str):
                    resulting_types.append(DataType(data_type))
                else:
                    resulting_types.append(data_type)

        # Get categories for the string data types.
        for i in xrange(len(resulting_types)):
            if resulting_types[i].is_equal("string") and resulting_types[i].categories == None:

                resulting_types[i] = DataType("string", categories=set(self.get_column(i)))