Search in sources :

Example 36 with Selection

use of tech.tablesaw.selection.Selection in project symja_android_library by axkr.

the class FloatIndex method atLeast.

public Selection atLeast(float value) {
    Selection selection = new BitmapBackedSelection();
    Float2ObjectSortedMap<IntArrayList> tail = index.tailMap(value);
    for (IntArrayList keys : tail.values()) {
        addAllToSelection(keys, selection);
    }
    return selection;
}
Also used : BitmapBackedSelection(tech.tablesaw.selection.BitmapBackedSelection) Selection(tech.tablesaw.selection.Selection) BitmapBackedSelection(tech.tablesaw.selection.BitmapBackedSelection) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList)

Example 37 with Selection

use of tech.tablesaw.selection.Selection in project symja_android_library by axkr.

the class Rows method tail.

public static void tail(int rowsToInclude, Table oldTable, Table newTable) {
    int oldTableSize = oldTable.rowCount();
    int start = oldTableSize - rowsToInclude;
    Selection rows = new BitmapBackedSelection(rowsToInclude);
    for (int i = start; i < oldTableSize; i++) {
        rows.add(i);
    }
    copyRowsToTable(rows, oldTable, newTable);
}
Also used : BitmapBackedSelection(tech.tablesaw.selection.BitmapBackedSelection) Selection(tech.tablesaw.selection.Selection) BitmapBackedSelection(tech.tablesaw.selection.BitmapBackedSelection)

Example 38 with Selection

use of tech.tablesaw.selection.Selection in project symja_android_library by axkr.

the class StandardTableSliceGroup method splitOn.

/**
 * Splits the sourceTable table into sub-tables, grouping on the columns whose names are given in
 * splitColumnNames
 */
private void splitOn(String... splitColumnNames) {
    Map<ByteArray, Selection> selectionMap = new LinkedHashMap<>();
    Map<ByteArray, String> sliceNameMap = new HashMap<>();
    List<Column<?>> splitColumns = getSourceTable().columns(splitColumnNames);
    if (containsTextColumn(splitColumns)) {
        for (int i = 0; i < getSourceTable().rowCount(); i++) {
            ByteArrayList byteArrayList = new ByteArrayList();
            StringBuilder stringKey = new StringBuilder();
            int count = 0;
            for (Column<?> col : splitColumns) {
                stringKey.append(col.getString(i));
                if (count < splitColumns.size() - 1) {
                    stringKey.append(SPLIT_STRING);
                }
                byteArrayList.addElements(byteArrayList.size(), col.asBytes(i));
                count++;
            }
            // Add to the matching selection.
            ByteArray byteArray = new ByteArray(byteArrayList.toByteArray());
            Selection selection = selectionMap.getOrDefault(byteArray, new BitmapBackedSelection());
            selection.add(i);
            selectionMap.put(byteArray, selection);
            sliceNameMap.put(byteArray, stringKey.toString());
        }
    } else {
        // handle the case where split is on non-text-columns
        int byteSize = getByteSize(splitColumns);
        for (int i = 0; i < getSourceTable().rowCount(); i++) {
            StringBuilder stringKey = new StringBuilder();
            ByteBuffer byteBuffer = ByteBuffer.allocate(byteSize);
            int count = 0;
            for (Column<?> col : splitColumns) {
                stringKey.append(col.getString(i));
                if (count < splitColumns.size() - 1) {
                    stringKey.append(SPLIT_STRING);
                }
                byteBuffer.put(col.asBytes(i));
                count++;
            }
            // Add to the matching selection.
            ByteArray byteArray = new ByteArray(byteBuffer.array());
            Selection selection = selectionMap.getOrDefault(byteArray, new BitmapBackedSelection());
            selection.add(i);
            selectionMap.put(byteArray, selection);
            sliceNameMap.put(byteArray, stringKey.toString());
        }
    }
    // Construct slices for all the values in our maps
    for (Entry<ByteArray, Selection> entry : selectionMap.entrySet()) {
        TableSlice slice = new TableSlice(getSourceTable(), entry.getValue());
        slice.setName(sliceNameMap.get(entry.getKey()));
        addSlice(slice);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) BitmapBackedSelection(tech.tablesaw.selection.BitmapBackedSelection) Selection(tech.tablesaw.selection.Selection) ByteBuffer(java.nio.ByteBuffer) LinkedHashMap(java.util.LinkedHashMap) Column(tech.tablesaw.columns.Column) CategoricalColumn(tech.tablesaw.api.CategoricalColumn) ByteArrayList(it.unimi.dsi.fastutil.bytes.ByteArrayList) BitmapBackedSelection(tech.tablesaw.selection.BitmapBackedSelection)

Example 39 with Selection

use of tech.tablesaw.selection.Selection in project symja_android_library by axkr.

the class DataFrameJoiner method createMultiColSelection.

/**
 * Create a big multicolumn selection for all join columns in the given table. Joins two tables.
 *
 * @param table the table that used to generate Selection.
 * @param ri row number of row in table.
 * @param indexes a reverse index for every join column in the table.
 * @param selectionSize max size in table .
 * @param joinColumnIndexes the column index of join key in tables
 * @return selection created
 */
private Selection createMultiColSelection(Table table, int ri, List<Index> indexes, int selectionSize, List<Integer> joinColumnIndexes) {
    Selection multiColSelection = Selection.withRange(0, selectionSize);
    int i = 0;
    for (Integer joinColumnIndex : joinColumnIndexes) {
        Column<?> col = table.column(joinColumnIndex);
        Selection oneColSelection = selectionForColumn(col, ri, indexes.get(i));
        // and the selections.
        multiColSelection = multiColSelection.and(oneColSelection);
        i++;
    }
    return multiColSelection;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Selection(tech.tablesaw.selection.Selection)

Example 40 with Selection

use of tech.tablesaw.selection.Selection in project symja_android_library by axkr.

the class RollingColumn method calc.

@SuppressWarnings({ "unchecked" })
public <INCOL extends Column<?>, OUT> Column<?> calc(AggregateFunction<INCOL, OUT> function) {
    // TODO: the subset operation copies the array. creating a view would likely be more efficient
    Column<?> result = function.returnType().create(generateNewColumnName(function));
    for (int i = 0; i < window - 1; i++) {
        result.appendMissing();
    }
    for (int origColIndex = 0; origColIndex < column.size() - window + 1; origColIndex++) {
        Selection selection = new BitmapBackedSelection();
        selection.addRange(origColIndex, origColIndex + window);
        INCOL subsetCol = (INCOL) column.subset(selection.toArray());
        OUT answer = function.summarize(subsetCol);
        if (answer instanceof Number) {
            Number number = (Number) answer;
            ((DoubleColumn) result).append(number.doubleValue());
        } else {
            result.appendObj(answer);
        }
    }
    return result;
}
Also used : DoubleColumn(tech.tablesaw.api.DoubleColumn) BitmapBackedSelection(tech.tablesaw.selection.BitmapBackedSelection) Selection(tech.tablesaw.selection.Selection) BitmapBackedSelection(tech.tablesaw.selection.BitmapBackedSelection)

Aggregations

Selection (tech.tablesaw.selection.Selection)85 BitmapBackedSelection (tech.tablesaw.selection.BitmapBackedSelection)80 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)31 PivotTable (tech.tablesaw.aggregate.PivotTable)3 BooleanColumn (tech.tablesaw.api.BooleanColumn)3 ByteOpenHashSet (it.unimi.dsi.fastutil.bytes.ByteOpenHashSet)2 IntIterator (it.unimi.dsi.fastutil.ints.IntIterator)2 IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)2 ShortOpenHashSet (it.unimi.dsi.fastutil.shorts.ShortOpenHashSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IExpr (org.matheclipse.core.interfaces.IExpr)2 ByteArrayList (it.unimi.dsi.fastutil.bytes.ByteArrayList)1 ByteIterator (it.unimi.dsi.fastutil.bytes.ByteIterator)1 IntRBTreeSet (it.unimi.dsi.fastutil.ints.IntRBTreeSet)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 CategoricalColumn (tech.tablesaw.api.CategoricalColumn)1 DoubleColumn (tech.tablesaw.api.DoubleColumn)1 Column (tech.tablesaw.columns.Column)1