From 0c13373b9167d62bddd8672a3cc837da98b884b8 Mon Sep 17 00:00:00 2001 From: Paul Andrey <paul.andrey@inria.fr> Date: Wed, 30 Aug 2023 12:20:55 +0200 Subject: [PATCH] Deprecate 'InMemoryDataset' JSON-dump (private) type-key use. --- declearn/dataset/_inmemory.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/declearn/dataset/_inmemory.py b/declearn/dataset/_inmemory.py index 18b546b6..5e64e053 100644 --- a/declearn/dataset/_inmemory.py +++ b/declearn/dataset/_inmemory.py @@ -19,7 +19,7 @@ import os import warnings -from typing import Any, ClassVar, Dict, Iterator, List, Optional, Set, Union +from typing import Any, Dict, Iterator, List, Optional, Set, Union import numpy as np import pandas as pd @@ -72,8 +72,6 @@ class InMemoryDataset(Dataset): # attributes serve clarity; pylint: disable=too-many-instance-attributes # arguments serve modularity; pylint: disable=too-many-arguments - _type_key: ClassVar[str] = "InMemoryDataset" - def __init__( self, data: Union[DataArray, str], @@ -313,7 +311,7 @@ class InMemoryDataset(Dataset): path = os.path.abspath(path) folder = os.path.dirname(path) info = {} # type: Dict[str, Any] - info["type"] = self._type_key + info["type"] = "InMemoryDataset" # NOTE: for backward compatibility # Optionally create data dumps. Record data dumps' paths. # fmt: off info["data"] = ( @@ -354,16 +352,11 @@ class InMemoryDataset(Dataset): if "config" not in dump: raise KeyError("Missing key in the JSON file: 'config'.") info = dump["config"] - for key in ("type", "data", "target", "s_wght", "f_cols"): + for key in ("data", "target", "s_wght", "f_cols"): if key not in info: error = f"Missing key in the JSON file: 'config/{key}'." raise KeyError(error) - key = info.pop("type") - if key != cls._type_key: - raise TypeError( - f"Incorrect 'type' field: got '{key}', " - f"expected '{cls._type_key}'." - ) + info.pop("type", None) # Instantiate the object and return it. return cls(**info) -- GitLab