# 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


from unittest import TestCase
from wallace.data_type_classification import DataTypeClassification
        self.assertEqual(False, DataTypeClassification.is_date("2-43-53"))
        self.assertEqual(False, DataTypeClassification.is_date("13-13-53"))
        self.assertEqual(False, DataTypeClassification.is_date("13/13/53"))
        self.assertEqual(False, DataTypeClassification.is_date("1/1/3"))

    def test_is_integer(self):
        self.assertEqual(True, DataTypeClassification.is_integer("1"))
        self.assertEqual(True, DataTypeClassification.is_integer("1435"))
        self.assertEqual(True, DataTypeClassification.is_integer("143523452345234523452345234523452345234523452345"))
        self.assertEqual(True, DataTypeClassification.is_integer("-234"))

        self.assertEqual(False, DataTypeClassification.is_integer("0."))
        self.assertEqual(False, DataTypeClassification.is_integer("-2.54"))
        self.assertEqual(False, DataTypeClassification.is_integer("-something"))
        self.assertEqual(False, DataTypeClassification.is_integer("5s3"))

    def test_is_float(self):
        self.assertEqual(True, DataTypeClassification.is_float("1."))
        self.assertEqual(True, DataTypeClassification.is_float("1435.345"))
        self.assertEqual(True, DataTypeClassification.is_float("143523452345234523452345234523452345234523.452345"))
        self.assertEqual(True, DataTypeClassification.is_float("-.234"))
        self.assertEqual(True, DataTypeClassification.is_float("5"))

        self.assertEqual(False, DataTypeClassification.is_float("-2.54shc"))
        self.assertEqual(False, DataTypeClassification.is_float("-something"))
        self.assertEqual(False, DataTypeClassification.is_float("5s3"))

    def test_is_boolean(self):
        self.assertEqual(True, DataTypeClassification.is_boolean("t"))
        self.assertEqual(True, DataTypeClassification.is_boolean("T"))

# 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: tests/dataset/test_data_type_classification.py
from unittest import TestCase
from wallace.data_type_classification import DataTypeClassification

        self.assertEqual(False, DataTypeClassification.is_date("2-43-53"))
        self.assertEqual(False, DataTypeClassification.is_date("13-13-53"))
        self.assertEqual(False, DataTypeClassification.is_date("13/13/53"))
        self.assertEqual(False, DataTypeClassification.is_date("1/1/3"))

    def test_is_integer(self):
        self.assertEqual(True, DataTypeClassification.is_integer("1"))
        self.assertEqual(True, DataTypeClassification.is_integer("1435"))
        self.assertEqual(True, DataTypeClassification.is_integer("143523452345234523452345234523452345234523452345"))
        self.assertEqual(True, DataTypeClassification.is_integer("-234"))

        self.assertEqual(False, DataTypeClassification.is_integer("0."))
        self.assertEqual(False, DataTypeClassification.is_integer("-2.54"))
        self.assertEqual(False, DataTypeClassification.is_integer("-something"))
        self.assertEqual(False, DataTypeClassification.is_integer("5s3"))

    def test_is_float(self):
        self.assertEqual(True, DataTypeClassification.is_float("1."))
        self.assertEqual(True, DataTypeClassification.is_float("1435.345"))
        self.assertEqual(True, DataTypeClassification.is_float("143523452345234523452345234523452345234523.452345"))
        self.assertEqual(True, DataTypeClassification.is_float("-.234"))
        self.assertEqual(True, DataTypeClassification.is_float("5"))

        self.assertEqual(False, DataTypeClassification.is_float("-2.54shc"))
        self.assertEqual(False, DataTypeClassification.is_float("-something"))
        self.assertEqual(False, DataTypeClassification.is_float("5s3"))

    def test_is_boolean(self):
        self.assertEqual(True, DataTypeClassification.is_boolean("t"))
        self.assertEqual(True, DataTypeClassification.is_boolean("T"))

        self.assertEqual(True, DataTypeClassification.is_boolean("true"))