1
1
from __future__ import annotations
2
2
3
- from typing import Any , Optional , Sequence
3
+ from typing import Optional , Sequence
4
4
5
5
import numpy
6
6
@@ -14,21 +14,41 @@ class InMemoryStorage:
14
14
"""Class responsible for storing/retrieving vectors in/from memory.
15
15
16
16
Attributes:
17
- _arrays: ?
18
- is_eternal: ?
17
+ _arrays: A dictionary containing data that has been stored in memory.
18
+ is_eternal: A boolean indicating whether the storage is eternal.
19
19
20
20
Args:
21
- is_eternal: ?
21
+ is_eternal: A boolean indicating whether the storage is eternal.
22
22
23
23
"""
24
24
25
- _arrays : Arrays
25
+ _arrays : Arrays = Arrays ({})
26
26
27
27
def __init__ (self , is_eternal : bool = False ) -> None :
28
- self ._arrays = Arrays ({})
29
28
self .is_eternal = is_eternal
30
29
31
- def get (self , period : types .Period ) -> Any :
30
+ def get (self , period : types .Period ) -> Optional [numpy .ndarray ]:
31
+ """Retrieve the data for the specified period from memory.
32
+
33
+ Args:
34
+ period: The period for which data should be retrieved.
35
+
36
+ Returns:
37
+ The data for the specified period, or None if no data is available.
38
+
39
+ Examples:
40
+ >>> storage = InMemoryStorage()
41
+ >>> value = numpy.array([1, 2, 3])
42
+ >>> instant = periods.Instant((2017, 1, 1))
43
+ >>> period = periods.Period(("year", instant, 1))
44
+
45
+ >>> storage.put(value, period)
46
+
47
+ >>> storage.get(period)
48
+ array([1, 2, 3])
49
+
50
+ """
51
+
32
52
period = _funcs .parse_period (period , self .is_eternal )
33
53
values = self ._arrays .get (period )
34
54
@@ -37,11 +57,50 @@ def get(self, period: types.Period) -> Any:
37
57
38
58
return values
39
59
40
- def put (self , value : Any , period : types .Period ) -> None :
60
+ def put (self , value : numpy .ndarray , period : types .Period ) -> None :
61
+ """Store the specified data in memory for the specified period.
62
+
63
+ Args:
64
+ value: The data to store
65
+ period: The period for which the data should be stored.
66
+
67
+ Examples:
68
+ >>> storage = InMemoryStorage()
69
+ >>> value = numpy.array([1, 2, 3])
70
+ >>> instant = periods.Instant((2017, 1, 1))
71
+ >>> period = periods.Period(("year", instant, 1))
72
+
73
+ >>> storage.put(value, period)
74
+
75
+ """
76
+
41
77
period = _funcs .parse_period (period , self .is_eternal )
42
78
self ._arrays = Arrays ({period : value , ** self ._arrays })
43
79
44
80
def delete (self , period : Optional [types .Period ] = None ) -> None :
81
+ """Delete the data for the specified period from memory.
82
+
83
+ Args:
84
+ period: The period for which data should be deleted. If not
85
+ specified, all data will be deleted.
86
+
87
+ Examples:
88
+ >>> storage = InMemoryStorage()
89
+ >>> value = numpy.array([1, 2, 3])
90
+ >>> instant = periods.Instant((2017, 1, 1))
91
+ >>> period = periods.Period(("year", instant, 1))
92
+
93
+ >>> storage.put(value, period)
94
+
95
+ >>> storage.get(period)
96
+ array([1, 2, 3])
97
+
98
+ >>> storage.delete(period)
99
+
100
+ >>> storage.get(period)
101
+
102
+ """
103
+
45
104
if period is None :
46
105
self ._arrays = Arrays ({})
47
106
return None
@@ -58,7 +117,7 @@ def get_known_periods(self) -> Sequence[types.Period]:
58
117
"""List of storage's known periods.
59
118
60
119
Returns:
61
- A list of periods.
120
+ A sequence containing the storage's known periods.
62
121
63
122
Examples:
64
123
>>> storage = InMemoryStorage()
0 commit comments