Ejemplo n.º 1
0
def read_csv(path):
    """ Read a csv file as a DataFrame

    Parameters
    ----------
    path : str
        path of the file

    Returns
    -------
    DataFrame

    """
    table = csv_weld.Table(path)

    new_columns = {}
    for column_name in table.columns:
        column = table.columns[column_name]
        weld_obj, weld_input_name = LazyResult.generate_placeholder_weld_object(column.data_id, column.encoder, column.decoder)
        new_columns[column_name] = LazyResult(weld_obj, numpy_to_weld_type(column.dtype), 1)

    random_column = new_columns[new_columns.keys()[0]]
    index_weld_obj = weld_range(0, 'len({})'.format(random_column.expr.weld_code), 1)
    index_weld_obj.update(random_column.expr)

    return DataFrame(new_columns, Index(index_weld_obj, np.dtype(np.int64)))
Ejemplo n.º 2
0
    def _create_variables(self):
        variables = OrderedDict()

        for kv in self.ds.variables.items():
            # generate a data_id to act as placeholder to the data
            data_id = LazyResult.generate_data_id(kv[0])
            weld_obj, weld_input_id = LazyResult.generate_placeholder_weld_object(
                data_id, Variable.encoder, Variable.decoder)

            variable = Variable(self.file_id, kv[0], kv[1].dimensions,
                                kv[1].shape, kv[1].__dict__, weld_obj,
                                kv[1].dtype)
            LazyResult.register_lazy_data(weld_input_id, variable)

            variables[kv[0]] = variable

        return variables