Skip to content

Commit

Permalink
docs(storage): add docs to on disk (#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Oct 4, 2024
1 parent 5848bae commit f8d5cfc
Showing 1 changed file with 64 additions and 8 deletions.
72 changes: 64 additions & 8 deletions openfisca_core/data_storage/on_disk_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,29 @@


class OnDiskStorage:
"""Storing and retrieving calculated vectors on disk."""
"""Storing and retrieving calculated vectors on disk.
Args:
storage_dir: Path to store calculated vectors.
is_eternal: Whether the storage is eternal.
preserve_storage_dir: Whether to preserve the storage directory.
"""

#: A dictionary containing data that has been stored on disk.
storage_dir: str

#: Whether the storage is eternal.
is_eternal: bool

#: Whether to preserve the storage directory.
preserve_storage_dir: bool

#: Mapping of file paths to possible Enum values.
_enums: dict

#: Mapping of periods to file paths.
_files: dict

def __init__(
self, storage_dir, is_eternal=False, preserve_storage_dir=False
Expand All @@ -21,8 +43,19 @@ def __init__(
self.storage_dir = storage_dir

def _decode_file(self, file):
"""
Examples
"""Decode a file by loading its contents as a ``numpy`` array.
Args:
file: Path to the file to be decoded.
Returns:
``numpy`` array or ``EnumArray`` representing the data in the file.
Note:
If the file is associated with ``Enum`` values, the array is
converted back to an ``EnumArray`` object.
Examples:
>>> import tempfile
>>> import numpy
Expand Down Expand Up @@ -54,7 +87,15 @@ def _decode_file(self, file):
return numpy.load(file)

def get(self, period):
"""
"""Retrieve the data for the specified period from disk.
Args:
period: The period for which data should be retrieved.
Returns:
A ``numpy`` array or ``EnumArray`` representing the vector for the
specified period, or ``None`` if no vector is stored.
Examples:
>>> import tempfile
Expand Down Expand Up @@ -84,7 +125,12 @@ def get(self, period):
return self._decode_file(values)

def put(self, value, period) -> None:
"""
"""Store the specified data on disk for the specified period.
Args:
value: The data to store
period: The period for which the data should be stored.
Examples:
>>> import tempfile
Expand Down Expand Up @@ -117,7 +163,12 @@ def put(self, value, period) -> None:
self._files[period] = path

def delete(self, period=None) -> None:
"""
"""Delete the data for the specified period from disk.
Args:
period: The period for which data should be deleted. If not
specified, all data will be deleted.
Examples:
>>> import tempfile
Expand Down Expand Up @@ -165,7 +216,11 @@ def delete(self, period=None) -> None:
}

def get_known_periods(self):
"""
"""List of storage's known periods.
Returns:
A sequence containing the storage's known periods.
Examples:
>>> import tempfile
Expand All @@ -192,7 +247,8 @@ def get_known_periods(self):
return self._files.keys()

def restore(self) -> None:
"""
"""Restore the storage from disk.
Examples:
>>> import tempfile
Expand Down

0 comments on commit f8d5cfc

Please sign in to comment.