Search in sources :

Example 6 with Row

use of tech.tablesaw.api.Row in project symja_android_library by axkr.

the class ASTDataset method select.

@Override
public IExpr select(IAST ast) {
    IExpr row = ast.arg1();
    IExpr column = ast.arg2();
    IExpr[] part = new IExpr[ast.size() - 3];
    IExpr result = select(row, column);
    if (part.length == 0) {
        return result;
    }
    if (result.isDataset()) {
        for (int i = 0; i < part.length; i++) {
            part[i] = ast.get(i + 3);
        }
        EvalEngine engine = EvalEngine.get();
        ASTDataset dataset = (ASTDataset) result;
        Table table = dataset.fTable;
        final List<String> names = table.columnNames();
        if (names.size() > 0) {
            Table resultTable = Table.create();
            Column<?>[] cols = new Column<?>[names.size()];
            for (int i = 0; i < names.size(); i++) {
                cols[i] = ExprColumn.create(names.get(i));
            }
            resultTable.addColumns(cols);
            for (int i = 0; i < table.rowCount(); i++) {
                Row currentRow = table.row(i);
                Row resultRow = resultTable.appendRow();
                for (int j = 0; j < table.columnCount(); j++) {
                    String columnName = names.get(j);
                    ColumnType t = currentRow.getColumnType(columnName);
                    IExpr arg = dataToExpr(table.get(i, j), t);
                    IExpr value = S.Part.of1(engine, arg, part);
                    if (value.isAST(S.Part) || !value.isPresent()) {
                        IASTAppendable missing = F.ast(S.Missing);
                        missing.append(F.$str("PartAbsent"));
                        missing.appendAll(part, 0, part.length);
                        value = missing;
                    }
                    resultRow.setExpr(columnName, value);
                }
            }
            return ASTDataset.newTablesawTable(resultTable);
        }
    }
    return F.NIL;
}
Also used : IASTDataset(org.matheclipse.core.interfaces.IASTDataset) Table(tech.tablesaw.api.Table) ColumnType(tech.tablesaw.api.ColumnType) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) Column(tech.tablesaw.columns.Column) ExprColumn(tech.tablesaw.api.ExprColumn) EvalEngine(org.matheclipse.core.eval.EvalEngine) IExpr(org.matheclipse.core.interfaces.IExpr) Row(tech.tablesaw.api.Row)

Aggregations

Row (tech.tablesaw.api.Row)6 IExpr (org.matheclipse.core.interfaces.IExpr)4 Column (tech.tablesaw.columns.Column)4 ArrayList (java.util.ArrayList)3 IAST (org.matheclipse.core.interfaces.IAST)3 IAssociation (org.matheclipse.core.interfaces.IAssociation)3 ExprColumn (tech.tablesaw.api.ExprColumn)3 Table (tech.tablesaw.api.Table)3 HashSet (java.util.HashSet)2 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)2 ColumnType (tech.tablesaw.api.ColumnType)2 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 EvalEngine (org.matheclipse.core.eval.EvalEngine)1 IASTDataset (org.matheclipse.core.interfaces.IASTDataset)1 IStringX (org.matheclipse.core.interfaces.IStringX)1 IntColumn (tech.tablesaw.api.IntColumn)1