Search in sources :

Example 56 with Selection

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

the class DoubleColumn method isIn.

public Selection isIn(final double... doubles) {
    final Selection results = new BitmapBackedSelection();
    final DoubleRBTreeSet doubleSet = new DoubleRBTreeSet(doubles);
    for (int i = 0; i < size(); i++) {
        if (doubleSet.contains(getDouble(i))) {
            results.add(i);
        }
    }
    return results;
}
Also used : BitmapBackedSelection(tech.tablesaw.selection.BitmapBackedSelection) Selection(tech.tablesaw.selection.Selection) BitmapBackedSelection(tech.tablesaw.selection.BitmapBackedSelection)

Example 57 with Selection

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

the class TextColumn method isNotIn.

@Override
public Selection isNotIn(Collection<String> strings) {
    Selection results = new BitmapBackedSelection();
    results.addRange(0, size());
    results.andNot(isIn(strings));
    return results;
}
Also used : BitmapBackedSelection(tech.tablesaw.selection.BitmapBackedSelection) Selection(tech.tablesaw.selection.Selection) BitmapBackedSelection(tech.tablesaw.selection.BitmapBackedSelection)

Example 58 with Selection

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

the class Rows method head.

public static void head(int rowCount, Table oldTable, Table newTable) {
    Selection rows = new BitmapBackedSelection(rowCount);
    for (int i = 0; i < rowCount; 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 59 with Selection

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

the class DataFrameJoiner method joinInternal.

/**
 * Joins two tables.
 *
 * @param table1 the table on the left side of the join.
 * @param table2 the table on the right side of the join.
 * @param joinType the type of join.
 * @param allowDuplicates if {@code false} the join will fail if any columns other than the join
 *     column have the same name if {@code true} the join will succeed and duplicate columns are
 *     renamed
 * @param keepAllJoinKeyColumns if {@code false} the join will only keep join key columns in
 *     table1 if {@code true} the join will return all join key columns in both table, which may
 *     have difference when there are null values
 * @param table2JoinColumnNames The names of the columns in table2 to join on.
 * @return the joined table
 */
private Table joinInternal(Table table1, Table table2, JoinType joinType, boolean allowDuplicates, boolean keepAllJoinKeyColumns, String... table2JoinColumnNames) {
    List<Integer> table2JoinColumnIndexes = getJoinIndexes(table2, table2JoinColumnNames);
    List<Index> table1Indexes = buildIndexesForJoinColumns(joinColumnIndexes, table1);
    List<Index> table2Indexes = buildIndexesForJoinColumns(table2JoinColumnIndexes, table2);
    Table result = Table.create(table1.name());
    // A set of column indexes in the result table that can be ignored. They are duplicate join
    // keys.
    Set<Integer> resultIgnoreColIndexes = emptyTableFromColumns(result, table1, table2, joinType, allowDuplicates, table2JoinColumnIndexes, keepAllJoinKeyColumns);
    validateIndexes(table1Indexes, table2Indexes);
    if (table1.rowCount() == 0 && (joinType == JoinType.LEFT_OUTER || joinType == JoinType.INNER)) {
        // that adds rows for full outer and right outer joins
        if (!keepAllJoinKeyColumns) {
            result.removeColumns(Ints.toArray(resultIgnoreColIndexes));
        }
        return result;
    }
    Selection table1DoneRows = Selection.with();
    Selection table2DoneRows = Selection.with();
    // use table 2 for row iteration, which can significantly increase performance
    if (table1.rowCount() > table2.rowCount() && joinType == JoinType.INNER) {
        for (Row row : table2) {
            int ri = row.getRowNumber();
            if (table2DoneRows.contains(ri)) {
                // Already processed a selection of table1 that contained this row.
                continue;
            }
            Selection table1Rows = createMultiColSelection(table2, ri, table1Indexes, table1.rowCount(), table2JoinColumnIndexes);
            Selection table2Rows = createMultiColSelection(table2, ri, table2Indexes, table2.rowCount(), table2JoinColumnIndexes);
            crossProduct(result, table1, table2, table1Rows, table2Rows, resultIgnoreColIndexes, keepAllJoinKeyColumns);
            table2DoneRows = table2DoneRows.or(table2Rows);
            if (table2DoneRows.size() == table2.rowCount()) {
                // Processed all the rows in table1 exit early.
                if (!keepAllJoinKeyColumns) {
                    result.removeColumns(Ints.toArray(resultIgnoreColIndexes));
                }
                return result;
            }
        }
    } else {
        for (Row row : table1) {
            int ri = row.getRowNumber();
            if (table1DoneRows.contains(ri)) {
                // Already processed a selection of table1 that contained this row.
                continue;
            }
            Selection table1Rows = createMultiColSelection(table1, ri, table1Indexes, table1.rowCount(), joinColumnIndexes);
            Selection table2Rows = createMultiColSelection(table1, ri, table2Indexes, table2.rowCount(), joinColumnIndexes);
            if ((joinType == JoinType.LEFT_OUTER || joinType == JoinType.FULL_OUTER) && table2Rows.isEmpty()) {
                withMissingLeftJoin(result, table1, table1Rows, resultIgnoreColIndexes, keepAllJoinKeyColumns);
            } else {
                crossProduct(result, table1, table2, table1Rows, table2Rows, resultIgnoreColIndexes, keepAllJoinKeyColumns);
            }
            table1DoneRows = table1DoneRows.or(table1Rows);
            if (joinType == JoinType.FULL_OUTER || joinType == JoinType.RIGHT_OUTER) {
                // Update done rows in table2 for full Outer.
                table2DoneRows = table2DoneRows.or(table2Rows);
            } else if (table1DoneRows.size() == table1.rowCount()) {
                // Processed all the rows in table1 exit early.
                if (!keepAllJoinKeyColumns) {
                    result.removeColumns(Ints.toArray(resultIgnoreColIndexes));
                }
                return result;
            }
        }
    }
    // Add all rows from table2 that were not handled already.
    Selection table2Rows = table2DoneRows.flip(0, table2.rowCount());
    withMissingRight(result, table1.columnCount(), table2, table2Rows, joinType, table2JoinColumnIndexes, resultIgnoreColIndexes, keepAllJoinKeyColumns);
    if (!keepAllJoinKeyColumns) {
        result.removeColumns(Ints.toArray(resultIgnoreColIndexes));
    }
    return result;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Selection(tech.tablesaw.selection.Selection)

Example 60 with Selection

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

the class IntIndex method lessThan.

public Selection lessThan(int value) {
    Selection selection = new BitmapBackedSelection();
    Int2ObjectSortedMap<IntArrayList> head = // we add 1 to get values equal to the arg
    index.headMap(value);
    for (IntArrayList keys : head.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)

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