Module omnipy.modules.json.datasets
Overview
View Source
from typing import Generic, TypeVar
from omnipy.data.dataset import Dataset
from ...data.model import Model
from .models import (JsonDictModel,
JsonDictOfDictsModel,
JsonDictOfDictsOfScalarsModel,
JsonDictOfListsModel,
JsonDictOfListsOfDictsModel,
JsonDictOfListsOfScalarsModel,
JsonDictOfNestedListsModel,
JsonDictOfScalarsModel,
JsonListModel,
JsonListOfDictsModel,
JsonListOfDictsOfScalarsModel,
JsonListOfListsModel,
JsonListOfListsOfScalarsModel,
JsonListOfNestedDictsModel,
JsonListOfScalarsModel,
JsonModel,
JsonNestedDictsModel,
JsonNestedListsModel,
JsonNoDictsModel,
JsonNoListsModel,
JsonScalarModel)
# TODO: switch from plural to singular for names of modules in omnipy modules
# TODO: call omnipy modules something else than modules, to distinguish from Python modules.
# Perhaps plugins?
#
JsonModelT = TypeVar('JsonModelT', bound=Model)
class JsonBaseDataset(Dataset[JsonModelT], Generic[JsonModelT]):
""""""
...
class JsonDataset(JsonBaseDataset[JsonModel]):
""""""
...
class JsonScalarDataset(JsonBaseDataset[JsonScalarModel]):
""""""
...
# List at the top level
class JsonListDataset(JsonBaseDataset[JsonListModel]):
""""""
...
class JsonListOfScalarsDataset(JsonBaseDataset[JsonListOfScalarsModel]):
""""""
...
class JsonListOfListsDataset(JsonBaseDataset[JsonListOfListsModel]):
""""""
...
class JsonListOfListsOfScalarsDataset(JsonBaseDataset[JsonListOfListsOfScalarsModel]):
""""""
...
class JsonListOfDictsDataset(JsonBaseDataset[JsonListOfDictsModel]):
""""""
...
class JsonListOfDictsOfScalarsDataset(JsonBaseDataset[JsonListOfDictsOfScalarsModel]):
""""""
...
# Dict at the top level
class JsonDictDataset(JsonBaseDataset[JsonDictModel]):
...
class JsonDictOfScalarsDataset(JsonBaseDataset[JsonDictOfScalarsModel]):
...
class JsonDictOfListsDataset(JsonBaseDataset[JsonDictOfListsModel]):
...
class JsonDictOfListsOfScalarsDataset(JsonBaseDataset[JsonDictOfListsOfScalarsModel]):
...
class JsonDictOfDictsDataset(JsonBaseDataset[JsonDictOfDictsModel]):
...
class JsonDictOfDictsOfScalarsDataset(JsonBaseDataset[JsonDictOfDictsOfScalarsModel]):
...
# Nested datasets
class JsonNoDictsDataset(JsonBaseDataset[JsonNoDictsModel]):
...
class JsonNestedListsDataset(JsonBaseDataset[JsonNestedListsModel]):
...
class JsonNoListsDataset(JsonBaseDataset[JsonNoListsModel]):
...
class JsonNestedDictsDataset(JsonBaseDataset[JsonNestedDictsModel]):
...
# More specific datasets
class JsonListOfNestedDictsDataset(JsonBaseDataset[JsonListOfNestedDictsModel]):
...
class JsonDictOfNestedListsDataset(JsonBaseDataset[JsonDictOfNestedListsModel]):
...
class JsonDictOfListsOfDictsDataset(JsonBaseDataset[JsonDictOfListsOfDictsModel]):
...
# Custom datasets
Variables
Classes
JsonBaseDataset
class JsonBaseDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonBaseDataset(Dataset[JsonModelT], Generic[JsonModelT]):
""""""
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonDataset
class JsonDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonDataset(JsonBaseDataset[JsonModel]):
""""""
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonDictDataset
class JsonDictDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonDictDataset(JsonBaseDataset[JsonDictModel]):
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonDictOfDictsDataset
class JsonDictOfDictsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonDictOfDictsDataset(JsonBaseDataset[JsonDictOfDictsModel]):
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonDictOfDictsOfScalarsDataset
class JsonDictOfDictsOfScalarsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonDictOfDictsOfScalarsDataset(JsonBaseDataset[JsonDictOfDictsOfScalarsModel]):
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonDictOfListsDataset
class JsonDictOfListsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonDictOfListsDataset(JsonBaseDataset[JsonDictOfListsModel]):
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonDictOfListsOfDictsDataset
class JsonDictOfListsOfDictsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonDictOfListsOfDictsDataset(JsonBaseDataset[JsonDictOfListsOfDictsModel]):
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonDictOfListsOfScalarsDataset
class JsonDictOfListsOfScalarsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonDictOfListsOfScalarsDataset(JsonBaseDataset[JsonDictOfListsOfScalarsModel]):
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonDictOfNestedListsDataset
class JsonDictOfNestedListsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonDictOfNestedListsDataset(JsonBaseDataset[JsonDictOfNestedListsModel]):
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonDictOfScalarsDataset
class JsonDictOfScalarsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonDictOfScalarsDataset(JsonBaseDataset[JsonDictOfScalarsModel]):
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonListDataset
class JsonListDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonListDataset(JsonBaseDataset[JsonListModel]):
""""""
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonListOfDictsDataset
class JsonListOfDictsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonListOfDictsDataset(JsonBaseDataset[JsonListOfDictsModel]):
""""""
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonListOfDictsOfScalarsDataset
class JsonListOfDictsOfScalarsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonListOfDictsOfScalarsDataset(JsonBaseDataset[JsonListOfDictsOfScalarsModel]):
""""""
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonListOfListsDataset
class JsonListOfListsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonListOfListsDataset(JsonBaseDataset[JsonListOfListsModel]):
""""""
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonListOfListsOfScalarsDataset
class JsonListOfListsOfScalarsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonListOfListsOfScalarsDataset(JsonBaseDataset[JsonListOfListsOfScalarsModel]):
""""""
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonListOfNestedDictsDataset
class JsonListOfNestedDictsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonListOfNestedDictsDataset(JsonBaseDataset[JsonListOfNestedDictsModel]):
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonListOfScalarsDataset
class JsonListOfScalarsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonListOfScalarsDataset(JsonBaseDataset[JsonListOfScalarsModel]):
""""""
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonNestedDictsDataset
class JsonNestedDictsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonNestedDictsDataset(JsonBaseDataset[JsonNestedDictsModel]):
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonNestedListsDataset
class JsonNestedListsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonNestedListsDataset(JsonBaseDataset[JsonNestedListsModel]):
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonNoDictsDataset
class JsonNoDictsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonNoDictsDataset(JsonBaseDataset[JsonNoDictsModel]):
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonNoListsDataset
class JsonNoListsDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonNoListsDataset(JsonBaseDataset[JsonNoListsModel]):
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result
JsonScalarDataset
class JsonScalarDataset(
value: Union[dict[str, object], Iterator[tuple[str, object]], pydantic.fields.UndefinedType] = PydanticUndefined,
*,
data: dict[str, object] | pydantic.fields.UndefinedType = PydanticUndefined,
**input_data: object
)
View Source
class JsonScalarDataset(JsonBaseDataset[JsonScalarModel]):
""""""
...
Class variables
Static methods
get_model_class
Returns the concrete Model class used for all data files in the dataset, e.g.:
Model[list[int]]
Returns:
Type | Description |
---|---|
Type[Model] |
The concrete Model class used for all data files in the dataset |
View Source
@classmethod
def get_model_class(cls) -> Type[Model]:
"""
Returns the concrete Model class used for all data files in the dataset, e.g.:
`Model[list[int]]`
:return: The concrete Model class used for all data files in the dataset
"""
model_type = cls.__fields__.get(DATA_KEY).type_
return cls._origmodel_if_annotated_optional(model_type)
to_json_schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
str |
dict[str, str] |
View Source
@classmethod
def to_json_schema(cls, pretty=False) -> str | dict[str, str]:
result = {}
schema = cls.schema()
for key, val in schema['properties']['data'].items():
result[key] = val
result['title'] = schema['title']
result['definitions'] = schema['definitions']
if pretty:
return cls._pretty_print_json(result)
else:
return json.dumps(result)
Methods
eq
Return self==value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object |
Returns:
Type | Description |
---|---|
bool |
View Source
def __eq__(self, other: object) -> bool:
# return self.__class__ == other.__class__ and super().__eq__(other)
return isinstance(other, Dataset) \
and self.__class__ == other.__class__ \
and self.data == other.data \
and self.to_data() == other.to_data() # last is probably unnecessary, but just in case
iter
so dict(model)
works
Returns:
Type | Description |
---|---|
Iterator |
View Source
def __iter__(self) -> Iterator:
return UserDict.__iter__(self)
setattr
Implement setattr(self, name, value).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str |
||
value |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setattr__(self, attr: str, value: Any) -> None:
if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
super().__setattr__(attr, value)
else:
raise RuntimeError('Model does not allow setting of extra attributes')
setitem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj_type |
str |
||
data_obj |
Any |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def __setitem__(self, obj_type: str, data_obj: Any) -> None:
has_prev_value = obj_type in self.data
prev_value = self.data.get(obj_type)
try:
self.data[obj_type] = data_obj
self._validate(obj_type)
except: # noqa
if has_prev_value:
self.data[obj_type] = prev_value
else:
del self.data[obj_type]
raise
as_multi_model_dataset
Returns:
Type | Description |
---|---|
'MultiModelDataset[ModelT]' |
View Source
def as_multi_model_dataset(self) -> 'MultiModelDataset[ModelT]':
multi_model_dataset = MultiModelDataset[self.get_model_class()]()
for obj_type in self:
multi_model_dataset.data[obj_type] = self.data[obj_type]
return multi_model_dataset
from_data
def from_data(
self,
data: Union[dict[str, Any], Iterator[tuple[str, Any]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, Any], Iterator[tuple[str, Any]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_data(self,
data: dict[str, Any] | Iterator[tuple[str, Any]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_data(obj_val)
self[obj_type] = new_model
from_json
def from_json(
self,
data: Union[dict[str, str], Iterator[tuple[str, str]]],
update: bool = True
) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[dict[str, str], Iterator[tuple[str, str]]] |
||
update |
bool |
True |
Returns:
Type | Description |
---|---|
NoneType |
View Source
def from_json(self,
data: dict[str, str] | Iterator[tuple[str, str]],
update: bool = True) -> None:
if not isinstance(data, dict):
data = dict(data)
if not update:
self.clear()
for obj_type, obj_val in data.items():
new_model = self.get_model_class()() # noqa
new_model.from_json(obj_val)
self[obj_type] = new_model
to_data
Returns:
Type | Description |
---|---|
dict[str, typing.Any] |
View Source
def to_data(self) -> dict[str, Any]:
return GenericModel.dict(self).get(DATA_KEY)
to_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretty |
Returns:
Type | Description |
---|---|
dict[str, str] |
View Source
def to_json(self, pretty=False) -> dict[str, str]:
result = {}
for key, val in self.to_data().items():
result[key] = self._pretty_print_json(val) if pretty else json.dumps(val)
return result