Base data wrapper
DataWrapper ¶
DataWrapper(
name,
usage=None,
derived_from=None,
inputs=None,
type=None,
)
Deprecated. Base class for DataWrapper.
Use DataWrapper subclasses to assign datasets to steps. The
Vectice library supports a handful of common cases. Additional
cases are generally easy to supply by deriving from this base
class. In particular, subclasses must override this class'
abstact methods (_build_metadata()
, _fetch_data()
).
Examples:
To create a custom data wrapper, inherit from DataWrapper
,
and implement the _build_metadata()
and _fetch_data()
methods:
from vectice.models.datasource.datawrapper import DataWrapper
from vectice.models.datasource.datawrapper.metadata import FilesMetadata
class MyDataWrapper(DataWrapper):
_origin = "Data source name"
def _build_metadata(self) -> FilesMetadata: # (1)
files = ... # fetch file list from your custom storage
total_size = ... # compute total file size
return FilesMetadata(
size=total_size,
origin=self._origin,
files=files,
usage=self.usage,
)
def _fetch_data(self) -> dict[str, bytes]:
files_data = {}
for file in self.metadata.files:
file_contents = ... # fetch file contents from your custom storage
files_data[file.name] = file_contents
return files_data
- Return FilesMetadata for data stored in files, DBMetadata for data stored in a database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the data wrapper. |
required |
usage |
DatasetSourceUsage | None
|
The usage of the dataset. |
None
|
derived_from |
list[int] | None
|
The list of dataset ids to create a new dataset from. |
None
|
inputs |
list[int] | None
|
Deprecated. Use |
None
|
type |
DatasetType | None
|
The type of the dataset. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
When both |
Source code in src/vectice/models/datasource/datawrapper/data_wrapper.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
data
property
¶
data: dict[str, bytes]
derived_from
property
¶
derived_from: list[int] | None
inputs
property
¶
inputs: list[int] | None
metadata
writable
property
¶
metadata: FilesMetadata
name
writable
property
¶
name: str
type
property
¶
type: DatasetType
usage
property
¶
usage: DatasetSourceUsage | None
The wrapper's dataset usage.
Returns:
Type | Description |
---|---|
DatasetSourceUsage | None
|
The wrapper's dataset usage. |