def reconcile_file_order(f, names=None, cats=None, write=False):
    # TODO: remove support for integer categories

    have_names = names is not None
    have_cats = cats is not None

    if not have_names and not have_cats:
        raise ValueError("reconcile_file_order needs names or cats...")

    if '_meta' in f:
        meta_group = f['_meta']

        have_f_names = 'names' in meta_group
        have_f_cats = 'cats' in meta_group
    else:
        meta_group = None
        have_f_names = have_f_cats = False

    if have_names:
        import h5py
        names = np.asarray(names, dtype=h5py.special_dtype(vlen=bytes))
    if have_f_names:
        f_names = meta_group['names'][()]

    if have_cats:
        cats, cats_is_str = _convert_cats(cats)
    if have_f_cats:
        f_cats, f_cats_is_str = _convert_cats(meta_group['cats'][()])

    # check name agreement, if both sides have it
    if have_names and have_f_names:
        assert np.all(names == f_names)

    # check category agreement
    if have_cats and have_f_cats:
        if cats_is_str and f_cats_is_str:
            assert np.all(cats == f_cats)
        else:
            # at least one, maybe both, are just ints
            # so we only want to check equivalence up to relabelings
            _, cats_relabeled = np.unique(cats, return_inverse=True)
            _, f_cats_relabeled = np.unique(f_cats, return_inverse=True)
            assert np.all(cats_relabeled == f_cats_relabeled)

    # Everything agrees to as much as we can check it.
    # Now it's time to write anything we have that the file doesn't.
    if write:
        if meta_group is None:
            meta_group = f.create_group('meta')
        if have_names and not have_f_names:
            meta_group['names'] = names
        if (have_cats and
                (not have_f_cats or (cats_is_str and not f_cats_is_str))):
            meta_group['cats'] = cats


# TODO: track flann algorithms used here? or just whether they're exact?
Checks that the passed names, cats agree with the cache file f. If both have
dataset/ETHPy150Open dougalsutherland/py-sdm/sdm/np_divs.py/reconcile_file_order