Mentions légales du service

Skip to content
Snippets Groups Projects
Verified Commit 0c13373b authored by ANDREY Paul's avatar ANDREY Paul
Browse files

Deprecate 'InMemoryDataset' JSON-dump (private) type-key use.

parent 87eada19
No related branches found
No related tags found
1 merge request!57Improve tests coverage and fix test-digged bugs
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
import os import os
import warnings 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 numpy as np
import pandas as pd import pandas as pd
...@@ -72,8 +72,6 @@ class InMemoryDataset(Dataset): ...@@ -72,8 +72,6 @@ class InMemoryDataset(Dataset):
# attributes serve clarity; pylint: disable=too-many-instance-attributes # attributes serve clarity; pylint: disable=too-many-instance-attributes
# arguments serve modularity; pylint: disable=too-many-arguments # arguments serve modularity; pylint: disable=too-many-arguments
_type_key: ClassVar[str] = "InMemoryDataset"
def __init__( def __init__(
self, self,
data: Union[DataArray, str], data: Union[DataArray, str],
...@@ -313,7 +311,7 @@ class InMemoryDataset(Dataset): ...@@ -313,7 +311,7 @@ class InMemoryDataset(Dataset):
path = os.path.abspath(path) path = os.path.abspath(path)
folder = os.path.dirname(path) folder = os.path.dirname(path)
info = {} # type: Dict[str, Any] 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. # Optionally create data dumps. Record data dumps' paths.
# fmt: off # fmt: off
info["data"] = ( info["data"] = (
...@@ -354,16 +352,11 @@ class InMemoryDataset(Dataset): ...@@ -354,16 +352,11 @@ class InMemoryDataset(Dataset):
if "config" not in dump: if "config" not in dump:
raise KeyError("Missing key in the JSON file: 'config'.") raise KeyError("Missing key in the JSON file: 'config'.")
info = dump["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: if key not in info:
error = f"Missing key in the JSON file: 'config/{key}'." error = f"Missing key in the JSON file: 'config/{key}'."
raise KeyError(error) raise KeyError(error)
key = info.pop("type") info.pop("type", None)
if key != cls._type_key:
raise TypeError(
f"Incorrect 'type' field: got '{key}', "
f"expected '{cls._type_key}'."
)
# Instantiate the object and return it. # Instantiate the object and return it.
return cls(**info) return cls(**info)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment