root_numpy.blockwise_inner_join

root_numpy.blockwise_inner_join(data, left, foreign_key, right, force_repeat=None, foreign_key_name=None)

Perform a blockwise inner join.

Perform a blockwise inner join from names specified in left to right via foreign_key: left->foreign_key->right.

Parameters:

data : array

A structured NumPy array.

left : array

Array of left side column names.

foreign_key : array or string

NumPy array or string foreign_key column name. This column can be either an integer or an array of ints. If foreign_key is an array of int column, left column will be treated according to left column type:

  • Scalar columns or columns in force_repeat will be repeated
  • Array columns not in force_repeat will be assumed to the same length as foreign_key and will be stretched by index

right : array

Array of right side column names. These are array columns that each index foreign_key points to. These columns are assumed to have the same length.

force_repeat : array, optional (default=None)

Array of left column names that will be forced to stretch even if it’s an array (useful when you want to emulate a multiple join).

foreign_key_name : str, optional (default=None)

The name of foreign key column in the output array.

Examples

>>> import numpy as np
>>> from root_numpy import blockwise_inner_join
>>> test_data = np.array([
(1.0, np.array([11, 12, 13]), np.array([1, 0, 1]), 0, np.array([1, 2, 3])),
(2.0, np.array([21, 22, 23]), np.array([-1, 2, -1]), 1, np.array([31, 32, 33]))],
dtype=[('sl', np.float), ('al', 'O'), ('fk', 'O'), ('s_fk', np.int), ('ar', 'O')])
>>> blockwise_inner_join(test_data, ['sl', 'al'], test_data['fk'], ['ar'])
array([(1.0, 11, 2, 1), (1.0, 12, 1, 0), (1.0, 13, 2, 1), (2.0, 22, 33, 2)],
dtype=[('sl', '<f8'), ('al', '<i8'), ('ar', '<i8'), ('fk', '<i8')])
>>> blockwise_inner_join(test_data, ['sl', 'al'], test_data['fk'], ['ar'], force_repeat=['al'])
array([(1.0, [11, 12, 13], 2, 1), (1.0, [11, 12, 13], 1, 0),
(1.0, [11, 12, 13], 2, 1), (2.0, [21, 22, 23], 33, 2)],
dtype=[('sl', '<f8'), ('al', '|O8'), ('ar', '<i8'), ('fk', '<i8')])