Serializers
Module containing all Serializers
Serializer
#
Bases: ABC
Abstract class from which all Serializer inherit from.
Source code in scrat/serializer/base.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
dump(obj, path)
abstractmethod
#
Save an object to disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Any
|
The result to save. |
required |
path |
Path
|
The target location in the filesystem. |
required |
Source code in scrat/serializer/base.py
11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
load(path)
abstractmethod
#
Load a saved object from disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
Location of the stored result. |
required |
Returns:
Type | Description |
---|---|
The object loaded into memory.
|
|
Source code in scrat/serializer/base.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
DillSerializer
#
Serializer using dill.
In order to use this Serializer dill needs to be installed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dump_kwargs |
Optional[Dict[str, Any]]
|
extra arguments for dill.dump, by default None |
None
|
load_kwargs |
Optional[Dict[str, Any]]
|
extra arguments for dill.load, by default None |
None
|
Source code in scrat/serializer/dill.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
JsonSerializer
#
Serializer that uses json from the python standard library.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dump_kwargs |
Optional[Dict[str, Any]]
|
Extra arguments for json.dump, by default None |
None
|
load_kwargs |
Optional[Dict[str, Any]]
|
Extra arguments for json.load, by default None |
None
|
Source code in scrat/serializer/json.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
NumpySerializer
#
Serializer for numpy arrays.
In order to use this Serializer numpy needs to be installed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save_kwargs |
Optional[Dict[str, Any]]
|
Extra arguments for numpy.save, by default None |
None
|
load_kwargs |
Optional[Dict[str, Any]]
|
Extra arguments for numpy.load, by default None |
None
|
Source code in scrat/serializer/numpy.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
PandasSerializer
#
Serializer for Pandas Series and DataFrames.
In order to use this Serializer pandas needs to be installed, some formats might need aditional libraries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format |
Union[str, Format]
|
Serialization method from the ones supported by pandas, by default Format.parquet |
parquet
|
to_kwargs |
Optional[Dict[str, Any]]
|
Extra arguments for the corresponding pandas.read_ |
None
|
read_kwargs |
Optional[Dict[str, Any]]
|
Extra arguments for the corresponding pandas.to_ |
None
|
Source code in scrat/serializer/pandas.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
PickleSerializer
#
Pickle serializer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dump_kwargs |
Optional[Dict[str, Any]]
|
Extra arguments for pickle.dump, by default None |
None
|
load_kwargs |
Optional[Dict[str, Any]]
|
Extra arguments for pickle.load, by default None |
None
|
Source code in scrat/serializer/pickle.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
get_default_serializer(func)
#
Try to find a sane serializer using the function's typehint.
Defaults to PickleSerializer
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable
|
The user function to be called |
required |
Returns:
Type | Description |
---|---|
An instance of the chosen Serializer
|
|
Source code in scrat/serializer/__init__.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|