use of tech.tablesaw.api.ColumnType 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;
}
use of tech.tablesaw.api.ColumnType in project symja_android_library by axkr.
the class Summarizer method apply.
/**
* Returns the result of applying to the functions to all the values in the appropriate column
* TODO add a test that uses a non numeric return type with apply
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public Table apply() {
if (groupColumnNames.length > 0) {
TableSliceGroup group = StandardTableSliceGroup.create(temp, groupColumnNames);
return summarize(group);
} else {
List<Table> results = new ArrayList<>();
ArrayListMultimap<String, AggregateFunction<?, ?>> reductionMultimap = getAggregateFunctionMultimap();
for (String name : reductionMultimap.keys()) {
List<AggregateFunction<?, ?>> reductions = reductionMultimap.get(name);
Table table = TableSliceGroup.summaryTableName(temp);
for (AggregateFunction function : reductions) {
Column column = temp.column(name);
Object result = function.summarize(column);
ColumnType type = function.returnType();
Column newColumn = type.create(TableSliceGroup.aggregateColumnName(name, function.functionName()));
if (result instanceof Number) {
Number number = (Number) result;
newColumn.append(number.doubleValue());
} else {
newColumn.append(result);
}
table.addColumns(newColumn);
}
results.add(table);
}
return (combineTables(results));
}
}
Aggregations