Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataProcessor objects with super() calls fail to pickle #49

Open
kostaleonard opened this issue Mar 26, 2022 · 1 comment
Open

DataProcessor objects with super() calls fail to pickle #49

kostaleonard opened this issue Mar 26, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@kostaleonard
Copy link
Owner

kostaleonard commented Mar 26, 2022

DataProcessor objects that make super() calls fail to pickle. This is an issue in dill that was apparently resolved in a recent PR, but there has not been a new release of the package to incorporate this change.

@kostaleonard kostaleonard added the bug Something isn't working label Mar 26, 2022
@kostaleonard kostaleonard added this to the Second release milestone Mar 26, 2022
@kostaleonard kostaleonard self-assigned this Mar 26, 2022
@kostaleonard
Copy link
Owner Author

kostaleonard commented Mar 26, 2022

As a workaround, you can do the following. This example is from tests/dataset/doubled_preset_data_processor.py.

Original:

class DoubledPresetDataProcessor(PresetDataProcessor):
    """Processes a preset dataset, with no file I/O; doubles tensor values."""

    def get_raw_features_and_labels(self, dataset_path: str) -> \
            Tuple[Dict[str, np.ndarray], Dict[str, np.ndarray]]:
        """Returns doubled preset raw feature and label tensors.

        :param dataset_path: Unused
        :return: A 2-tuple of the features dictionary and labels dictionary,
            with matching keys and ordered tensors.
        """
        # This will cause a pickling error.
        features, labels = super().get_raw_features_and_labels(dataset_path)
        for name, tensor in features.items():
            features[name] = 2 * tensor
        return features, labels

Workaround:

class DoubledPresetDataProcessor(PresetDataProcessor):
    """Processes a preset dataset, with no file I/O; doubles tensor values."""

    def get_raw_features_and_labels(self, dataset_path: str) -> \
            Tuple[Dict[str, np.ndarray], Dict[str, np.ndarray]]:
        """Returns doubled preset raw feature and label tensors.

        :param dataset_path: Unused
        :return: A 2-tuple of the features dictionary and labels dictionary,
            with matching keys and ordered tensors.
        """
        # See #49 for why we can't use super().
        features, labels = PresetDataProcessor.get_raw_features_and_labels(
            self, dataset_path)
        for name, tensor in features.items():
            features[name] = 2 * tensor
        return features, labels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant