Skip to content

declearn.dataset.load_dataset_from_json

DEPRECATED Instantiate a dataset based on a JSON dump file.

Parameters:

Name Type Description Default
path str

Path to a JSON file output by the save_to_json method of the Dataset that is being reloaded. The actual type of dataset should be specified under the "name" field of that file.

required

Returns:

Name Type Description
dataset Dataset

Dataset (subclass) instance, reloaded from JSON.

Raises:

Type Description
NotImplementedError

If the target Dataset does not implement a load_from_json method (which was removed from the API in DecLearn 2.3.0).

Source code in declearn/dataset/_base.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
def load_dataset_from_json(path: str) -> Dataset:  # pragma: no cover
    """DEPRECATED Instantiate a dataset based on a JSON dump file.

    Parameters
    ----------
    path: str
        Path to a JSON file output by the `save_to_json`
        method of the Dataset that is being reloaded.
        The actual type of dataset should be specified
        under the "name" field of that file.

    Returns
    -------
    dataset: Dataset
        Dataset (subclass) instance, reloaded from JSON.

    Raises
    ------
    NotImplementedError
        If the target `Dataset` does not implement a `load_from_json`
        method (which was removed from the API in DecLearn 2.3.0).
    """
    warnings.warn(
        "'load_dataset_from_json' was deprecated in Declearn 2.4.0, after"
        "'Dataset.load_from_json' was removed from the API in v2.3.0. It "
        "may raise a 'NotImplementedError', and will be removed in DecLearn "
        "2.6 and/or 3.0.",
        category=DeprecationWarning,
        stacklevel=2,
    )
    dump = json_load(path)
    cls = access_registered(dump["name"], group="Dataset")
    if not hasattr(cls, "load_from_json"):
        raise NotImplementedError(
            f"Dataset class '{cls}' does not implement 'load_from_json'."
        )
    return cls.load_from_json(path)