def __init__(self, schema, data=None): """ Expects schema to as list of tuples """ # Can afford a richer object since it will be reused per row, with more init up front to save calculation standardized_schema = [(name, valid_data_types.get_from_type(t)) for name, t in schema] self.__schema_dict = OrderedDict(standardized_schema) self.__data = [] if data is None else data # data is an array of strings right now self.__dtypes = self.__schema_dict.values() self.__indices_dict = dict([(k, i) for i, k, in enumerate(self.__schema_dict.keys())]) self.__dtype_constructors = [valid_data_types.get_constructor(t) for t in self.__dtypes]
def __init__(self, schema, data=None): """ Expects schema to as list of tuples """ # Can afford a richer object since it will be reused per row, with more init up front to save calculation standardized_schema = [(name, valid_data_types.get_from_type(t)) for name, t in schema] self.__schema_dict = OrderedDict(standardized_schema) self.__data = [] if data is None else data # data is an array of strings right now self.__dtypes = self.__schema_dict.values() self.__indices_dict = dict([(k, i) for i, k, in enumerate(self.__schema_dict.keys())]) self.__dtype_constructors = [valid_data_types.get_constructor(t) for t in self.__dtypes]
def _validate(self): validated_schema = [] for field in self.schema: name = field[0] if not isinstance(name, basestring): raise ValueError("First item in CSV schema tuple must be a string") try: data_type = valid_data_types.get_from_type(field[1]) except ValueError: raise ValueError("Second item in CSV schema tuple must be a supported type: " + str(valid_data_types)) else: validated_schema.append((name, data_type)) self.schema = validated_schema
def _validate(self): validated_schema = [] for field in self.schema: name = field[0] if not isinstance(name, basestring): raise ValueError("First item in schema tuple must be a string") try: data_type = valid_data_types.get_from_type(field[1]) except ValueError: raise ValueError("Second item in schema tuple must be a supported type: " + str(valid_data_types)) else: validated_schema.append((name, data_type)) self.schema = validated_schema
def __init__(self, frame, name, data_type): self.name = name self.data_type = valid_data_types.get_from_type(data_type) self._frame = frame
def __init__(self, frame, name, data_type): self.name = name self.data_type = valid_data_types.get_from_type(data_type) self._frame = frame