def get_group_index(labels, shape, sort, xnull):
def _int64_cut_off(shape):<EOL><INDENT>acc = <NUM_LIT:1><EOL>for i, mul in enumerate(shape):<EOL><INDENT>acc *= int(mul)<EOL>if not acc < _INT64_MAX:<EOL><INDENT>return i<EOL><DEDENT><DEDENT>return len(shape)<EOL><DEDENT>def maybe_lift(lab, size):<EOL><INDENT>return (lab + <NUM_LIT:1>, size + <NUM_LIT:1>) if (lab == -<NUM_LIT:1>).any() else (lab, size)<EOL><DEDENT>labels = map(ensure_int64, labels)<EOL>if not xnull:<EOL><INDENT>labels, shape = map(list, zip(*map(maybe_lift, labels, shape)))<EOL><DEDENT>labels = list(labels)<EOL>shape = list(shape)<EOL>while True:<EOL><INDENT>nlev = _int64_cut_off(shape)<EOL>stride = np.prod(shape[<NUM_LIT:1>:nlev], dtype='<STR_LIT>')<EOL>out = stride * labels[<NUM_LIT:0>].astype('<STR_LIT>', subok=False, copy=False)<EOL>for i in range(<NUM_LIT:1>, nlev):<EOL><INDENT>if shape[i] == <NUM_LIT:0>:<EOL><INDENT>stride = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>stride //= shape[i]<EOL><DEDENT>out += labels[i] * stride<EOL><DEDENT>if xnull:  <EOL><INDENT>mask = labels[<NUM_LIT:0>] == -<NUM_LIT:1><EOL>for lab in labels[<NUM_LIT:1>:nlev]:<EOL><INDENT>mask |= lab == -<NUM_LIT:1><EOL><DEDENT>out[mask] = -<NUM_LIT:1><EOL><DEDENT>if nlev == len(shape):  <EOL><INDENT>break<EOL><DEDENT>comp_ids, obs_ids = compress_group_index(out, sort=sort)<EOL>labels = [comp_ids] + labels[nlev:]<EOL>shape = [len(obs_ids)] + shape[nlev:]<EOL><DEDENT>return out<EOL>
For the particular label_list, gets the offsets into the hypothetical list
representing the totally ordered cartesian product of all possible label
combinations, *as long as* this space fits within int64 bounds;
otherwise, though group indices identify unique combinations of
labels, they cannot be deconstructed.
- If `sort`, rank of returned ids preserve lexical ranks of labels.
  i.e. returned id's can be used to do lexical sort on labels;
- If `xnull` nulls (-1 labels) are passed through.

Parameters
----------
labels: sequence of arrays
    Integers identifying levels at each location
shape: sequence of ints same length as labels
    Number of unique levels at each location
sort: boolean
    If the ranks of returned ids should match lexical ranks of labels
xnull: boolean
    If true nulls are excluded. i.e. -1 values in the labels are
    passed through
Returns
-------
An array of type int64 where two elements are equal if their corresponding
labels are equal at all location.