Ejemplo n.º 1
0
 def setUpDB(self):
     self.data = [
         [1, 2, 3, None, 'm'],
         [2, 3, 1, 4, 'f'],
         [None, None, None, None, None],
         [7, None, 3, None, 'f'],
     ]
     self.conn, self.table_name = self.create_sql_table(self.data)
     table = SqlTable(self.conn, self.table_name, inspect_values=True)
     variables = table.domain.variables
     new_table = table.copy()
     new_table.domain = domain.Domain(variables[:-1], variables[-1:])
     self.table = new_table
Ejemplo n.º 2
0
 def setUp(self):
     self.data = [
         [1, 2, 3, None, 'm'],
         [2, 3, 1, 4, 'f'],
         [None, None, None, None, None],
         [7, None, 3, None, 'f'],
     ]
     self.table_uri = self.create_sql_table(self.data)
     table = SqlTable(self.table_uri)
     variables = table.domain.variables
     new_table = table.copy()
     new_table.domain = domain.Domain(variables[:-1], variables[-1:])
     self.table = new_table
Ejemplo n.º 3
0
    def __getitem__(self, key):
        if isinstance(key, int):
            return RowInstance(self, key)
        if not isinstance(key, tuple):
            return Table.from_table_rows(self, key)

        if len(key) != 2:
            raise IndexError("Table indices must be one- or two-dimensional")

        row_idx, col_idx = key
        if isinstance(row_idx, int):
            try:
                col_idx = self.domain.index(col_idx)
                var = self.domain[col_idx]
                if 0 <= col_idx < len(self.domain.attributes):
                    return Value(var, self.X[row_idx, col_idx])
                elif col_idx >= len(self.domain.attributes):
                    return Value(
                        var, self.Y[row_idx,
                                    col_idx - len(self.domain.attributes)])
                elif col_idx < 0:
                    return Value(var, self.metas[row_idx, -1 - col_idx])
            except TypeError:
                row_idx = [row_idx]

        # multiple rows OR single row but multiple columns:
        # construct a new table
        attributes, col_indices = self._compute_col_indices(col_idx)
        if attributes is not None:
            n_attrs = len(self.domain.attributes)
            r_attrs = [
                attributes[i] for i, col in enumerate(col_indices)
                if 0 <= col < n_attrs
            ]
            r_classes = [
                attributes[i] for i, col in enumerate(col_indices)
                if col >= n_attrs
            ]
            r_metas = [
                attributes[i] for i, col in enumerate(col_indices) if col < 0
            ]
            domain = orange_domain.Domain(r_attrs, r_classes, r_metas)
        else:
            domain = self.domain
        return Table.from_table(domain, self, row_idx)