def check_key(data_object, key, cardinal=False):
itype = (int, np.int32, np.int64)<EOL>if not isinstance(key, itype + (slice, tuple, list, np.ndarray)):<EOL><INDENT>raise KeyError("<STR_LIT>".format(type(key), key))<EOL><DEDENT>keys = data_object.index.values<EOL>if cardinal and data_object._cardinal is not None:<EOL><INDENT>keys = data_object[data_object._cardinal[<NUM_LIT:0>]].unique()<EOL><DEDENT>elif isinstance(key, itype) and key in keys:<EOL><INDENT>key = list(sorted(data_object.index.values[key]))<EOL><DEDENT>elif isinstance(key, itype) and key < <NUM_LIT:0>:<EOL><INDENT>key = list(sorted(data_object.index.values[key]))<EOL><DEDENT>elif isinstance(key, itype):<EOL><INDENT>key = [key]<EOL><DEDENT>elif isinstance(key, slice):<EOL><INDENT>key = list(sorted(data_object.index.values[key]))<EOL><DEDENT>elif isinstance(key, (tuple, list, pd.Index)) and not np.all(k in keys for k in key):<EOL><INDENT>key = list(sorted(data_object.index.values[key]))<EOL><DEDENT>return key<EOL>
Update the value of an index key by matching values or getting positionals.