def depickle_legacy_package_name_compatible(pickled_string):
    """Backward compatible way of depickling old pickled strings.

    Previously petastorm package was named differently. In order to be able to load older datasets, we modify
    module names in the pickled stream with the new ones.

    :param pickled_string: A pickled string to be passed to pickle.loads
    :return:
    """
    LEGACY_PACKAGE_NAMES = ['av.experimental.deepdrive.dataset_toolkit', 'av.ml.dataset_toolkit']
    LEGACY_MODULES = ['codecs', 'unischema', 'sequence']

    for legacy_package_name in LEGACY_PACKAGE_NAMES:
        for legacy_module in LEGACY_MODULES:
            # Substitute module names directly in the pickled stream. Encode as 'ascii' to make sure no non-ascii
            # character made its way into package/module name
            legacy_package_entry = '\n(c{}.{}\n'.format(legacy_package_name, legacy_module).encode('ascii')
            new_module_name = '\n(cpetastorm.{}\n'.format(legacy_module).encode('ascii')
            modified_pickled_string = pickled_string.replace(legacy_package_entry, new_module_name)
            if modified_pickled_string != pickled_string:
                logger.warning('Depickling "%s.%s" which has moved to "petastorm.%s". '
                               'Regenerate metadata.', legacy_package_name, legacy_module, legacy_module)

            pickled_string = modified_pickled_string

    return restricted_loads(pickled_string)
Backward compatible way of depickling old pickled strings.

    Previously petastorm package was named differently. In order to be able to load older datasets, we modify
    module names in the pickled stream with the new ones.

    :param pickled_string: A pickled string to be passed to pickle.loads
    :return:
    
petastorm/etl/legacy.py