Skip to content

nb module

Numba-compiled functions for records and mapped arrays.

Provides an arsenal of Numba-compiled functions for records and mapped arrays. These only accept NumPy arrays and other Numba-compatible types.

Note

All functions passed as argument must be Numba-compiled.

Records must retain the order they were created in.


ol_ignore_unstack_mapped_nb function

_ignore_unstack_mapped_nb(
    mapped_arr,
    col_map,
    fill_value
)

ol_repeat_unstack_mapped_nb function

_repeat_unstack_mapped_nb(
    mapped_arr,
    col_arr,
    idx_arr,
    repeat_cnt_arr,
    n_cols,
    fill_value
)

ol_unstack_mapped_nb function

_unstack_mapped_nb(
    mapped_arr,
    col_arr,
    idx_arr,
    target_shape,
    fill_value
)

apply_meta_nb function

apply_meta_nb(
    n_values,
    col_map,
    apply_func_nb,
    *args
)

Meta version of apply_nb().

apply_func_nb must accept the indices, the column index, and *args. Must return an array.


apply_nb function

apply_nb(
    arr,
    col_map,
    apply_func_nb,
    *args
)

Apply function on mapped array or records per column.

Returns the same shape as arr.

apply_func_nb must accept the values of the column and *args. Must return an array.


bottom_n_mapped_nb function

bottom_n_mapped_nb(
    mapped_arr,
    col_map,
    n
)

Returns the mask of the bottom N mapped elements.


col_lens_nb function

col_lens_nb(
    col_arr,
    n_cols
)

Get column lengths from sorted column array.

Note

Requires col_arr to be in ascending order. This can be done by sorting.


col_map_nb function

col_map_nb(
    col_arr,
    n_cols
)

Build a map between columns and value indices.

Returns an array with indices segmented by column and an array with column lengths.

Works well for unsorted column arrays.


first_n_nb function

first_n_nb(
    col_map,
    n
)

Returns the mask of the first N elements.


generate_ids_nb function

generate_ids_nb(
    col_arr,
    n_cols
)

Generate the monotonically increasing id array based on the column index array.


ignore_unstack_mapped_nb function

ignore_unstack_mapped_nb(
    mapped_arr,
    col_map,
    fill_value
)

Unstack mapped array by ignoring index data.


is_col_id_sorted_nb function

is_col_id_sorted_nb(
    col_arr,
    id_arr
)

Check whether the column and id arrays are sorted.


is_col_sorted_nb function

is_col_sorted_nb(
    col_arr
)

Check whether the column array is sorted.


last_n_nb function

last_n_nb(
    col_map,
    n
)

Returns the mask of the last N elements.


map_records_meta_nb function

map_records_meta_nb(
    n_values,
    map_func_nb,
    *args
)

Meta version of map_records_nb().

map_func_nb must accept the record index and *args. Must return a single value.


map_records_nb function

map_records_nb(
    records,
    map_func_nb,
    *args
)

Map each record to a single value.

map_func_nb must accept a single record and *args. Must return a single value.


mapped_coverage_map_nb function

mapped_coverage_map_nb(
    col_arr,
    idx_arr,
    target_shape
)

Get the coverage map of a mapped array.

Each element corresponds to the number of times it was referenced (= duplicates of col_arr and idx_arr). More than one depicts a positional conflict.


mapped_has_conflicts_nb function

mapped_has_conflicts_nb(
    col_arr,
    idx_arr,
    target_shape
)

Check whether mapped array has positional conflicts.


mapped_value_counts_nb function

mapped_value_counts_nb(
    mapped_arr,
    n_uniques
)

Get value counts globally of an already factorized mapped array.


mapped_value_counts_per_col_nb function

mapped_value_counts_per_col_nb(
    codes,
    n_uniques,
    col_map
)

Get value counts per column/group of an already factorized mapped array.


mapped_value_counts_per_row_nb function

mapped_value_counts_per_row_nb(
    mapped_arr,
    n_uniques,
    idx_arr,
    n_rows
)

Get value counts per row of an already factorized mapped array.


random_n_nb function

random_n_nb(
    col_map,
    n
)

Returns the mask of random N elements.


record_col_lens_select_nb function

record_col_lens_select_nb(
    records,
    col_lens,
    new_cols
)

Perform indexing on sorted records using column lengths.

Returns new records.


record_col_map_select_nb function

record_col_map_select_nb(
    records,
    col_map,
    new_cols
)

Same as record_col_lens_select_nb() but using column map col_map.


reduce_mapped_meta_nb function

reduce_mapped_meta_nb(
    col_map,
    fill_value,
    reduce_func_nb,
    *args
)

Meta version of reduce_mapped_nb().

reduce_func_nb must accept the mapped indices, the column index, and *args. Must return a single value.


reduce_mapped_nb function

reduce_mapped_nb(
    mapped_arr,
    col_map,
    fill_value,
    reduce_func_nb,
    *args
)

Reduce mapped array by column to a single value.

Faster than unstack_mapped_nb() and vbt.* used together, and also requires less memory. But does not take advantage of caching.

reduce_func_nb must accept the mapped array and *args. Must return a single value.


reduce_mapped_segments_nb function

reduce_mapped_segments_nb(
    mapped_arr,
    idx_arr,
    id_arr,
    col_map,
    segment_arr,
    reduce_func_nb,
    *args
)

Reduce each segment of values in mapped array.

Uses the last column, index, and id of each segment for the new value.

reduce_func_nb must accept the values in the segment and *args. Must return a single value.

Note

Groups must come in ascending order per column, and idx_arr and id_arr must come in ascending order per segment of values.


reduce_mapped_to_array_meta_nb function

reduce_mapped_to_array_meta_nb(
    col_map,
    fill_value,
    reduce_func_nb,
    *args
)

Meta version of reduce_mapped_to_array_nb().

reduce_func_nb is the same as in reduce_mapped_meta_nb().


reduce_mapped_to_array_nb function

reduce_mapped_to_array_nb(
    mapped_arr,
    col_map,
    fill_value,
    reduce_func_nb,
    *args
)

Reduce mapped array by column to an array.

reduce_func_nb same as for reduce_mapped_nb() but must return an array.


reduce_mapped_to_idx_array_meta_nb function

reduce_mapped_to_idx_array_meta_nb(
    col_map,
    idx_arr,
    fill_value,
    reduce_func_nb,
    *args
)

Meta version of reduce_mapped_to_idx_array_nb().

reduce_func_nb is the same as in reduce_mapped_meta_nb().


reduce_mapped_to_idx_array_nb function

reduce_mapped_to_idx_array_nb(
    mapped_arr,
    col_map,
    idx_arr,
    fill_value,
    reduce_func_nb,
    *args
)

Reduce mapped array by column to an index array.

Same as reduce_mapped_to_array_nb() except idx_arr must be passed.

Note

Must return integers or raise an exception.


reduce_mapped_to_idx_meta_nb function

reduce_mapped_to_idx_meta_nb(
    col_map,
    idx_arr,
    fill_value,
    reduce_func_nb,
    *args
)

Meta version of reduce_mapped_to_idx_nb().

reduce_func_nb is the same as in reduce_mapped_meta_nb().


reduce_mapped_to_idx_nb function

reduce_mapped_to_idx_nb(
    mapped_arr,
    col_map,
    idx_arr,
    fill_value,
    reduce_func_nb,
    *args
)

Reduce mapped array by column to an index.

Same as reduce_mapped_nb() except idx_arr must be passed.

Note

Must return integers or raise an exception.


repeat_unstack_mapped_nb function

repeat_unstack_mapped_nb(
    mapped_arr,
    col_arr,
    idx_arr,
    repeat_cnt_arr,
    n_cols,
    fill_value
)

Unstack mapped array using repeated index data.


top_n_mapped_nb function

top_n_mapped_nb(
    mapped_arr,
    col_map,
    n
)

Returns the mask of the top N mapped elements.


unstack_index_nb function

unstack_index_nb(
    repeat_cnt_arr
)

Unstack index using the number of times each element must repeat.

repeat_cnt_arr can be created from the coverage map.


unstack_mapped_nb function

unstack_mapped_nb(
    mapped_arr,
    col_arr,
    idx_arr,
    target_shape,
    fill_value
)

Unstack mapped array using index data.