pastastore 1.3.0__py3-none-any.whl → 1.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pastastore/__init__.py +3 -5
- pastastore/base.py +204 -58
- pastastore/connectors.py +51 -30
- pastastore/datasets.py +3 -2
- pastastore/plotting.py +136 -30
- pastastore/store.py +201 -35
- pastastore/styling.py +67 -0
- pastastore/util.py +48 -16
- pastastore/version.py +32 -1
- pastastore/yaml_interface.py +33 -25
- {pastastore-1.3.0.dist-info → pastastore-1.5.0.dist-info}/METADATA +12 -10
- pastastore-1.5.0.dist-info/RECORD +15 -0
- {pastastore-1.3.0.dist-info → pastastore-1.5.0.dist-info}/WHEEL +1 -1
- pastastore-1.3.0.dist-info/RECORD +0 -14
- {pastastore-1.3.0.dist-info → pastastore-1.5.0.dist-info}/LICENSE +0 -0
- {pastastore-1.3.0.dist-info → pastastore-1.5.0.dist-info}/top_level.txt +0 -0
pastastore/connectors.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"""Module containing classes for connecting to different data stores."""
|
|
2
|
+
|
|
1
3
|
import json
|
|
2
4
|
import os
|
|
3
5
|
import warnings
|
|
@@ -16,11 +18,12 @@ warnings.showwarning = _custom_warning
|
|
|
16
18
|
|
|
17
19
|
|
|
18
20
|
class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
21
|
+
"""ArcticConnector object that connects to a running MongoDB database via Arctic."""
|
|
22
|
+
|
|
19
23
|
conn_type = "arctic"
|
|
20
24
|
|
|
21
25
|
def __init__(self, name: str, connstr: str):
|
|
22
|
-
"""Create an ArcticConnector object that connects to a
|
|
23
|
-
database via Arctic.
|
|
26
|
+
"""Create an ArcticConnector object that connects to a MongoDB database.
|
|
24
27
|
|
|
25
28
|
Parameters
|
|
26
29
|
----------
|
|
@@ -29,6 +32,12 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
29
32
|
connstr : str
|
|
30
33
|
connection string (e.g. 'mongodb://localhost:27017/')
|
|
31
34
|
"""
|
|
35
|
+
warnings.warn(
|
|
36
|
+
"ArcticConnector is deprecated. Please use a different "
|
|
37
|
+
"connector, e.g. `pst.ArcticDBConnector`.",
|
|
38
|
+
DeprecationWarning,
|
|
39
|
+
stacklevel=1,
|
|
40
|
+
)
|
|
32
41
|
try:
|
|
33
42
|
import arctic
|
|
34
43
|
except ModuleNotFoundError as e:
|
|
@@ -52,8 +61,7 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
52
61
|
self._update_all_oseries_model_links()
|
|
53
62
|
|
|
54
63
|
def _initialize(self) -> None:
|
|
55
|
-
"""
|
|
56
|
-
|
|
64
|
+
"""Initialize the libraries (internal method)."""
|
|
57
65
|
for libname in self._default_library_names:
|
|
58
66
|
if self._library_name(libname) not in self.arc.list_libraries():
|
|
59
67
|
self.arc.initialize_library(self._library_name(libname))
|
|
@@ -66,7 +74,7 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
66
74
|
self.libs[libname] = self._get_library(libname)
|
|
67
75
|
|
|
68
76
|
def _library_name(self, libname: str) -> str:
|
|
69
|
-
"""
|
|
77
|
+
"""Get full library name according to Arctic (internal method)."""
|
|
70
78
|
return ".".join([self.name, libname])
|
|
71
79
|
|
|
72
80
|
def _get_library(self, libname: str):
|
|
@@ -94,7 +102,7 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
94
102
|
metadata: Optional[Dict] = None,
|
|
95
103
|
**_,
|
|
96
104
|
) -> None:
|
|
97
|
-
"""
|
|
105
|
+
"""Add item to library (time series or model) (internal method).
|
|
98
106
|
|
|
99
107
|
Parameters
|
|
100
108
|
----------
|
|
@@ -111,7 +119,7 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
111
119
|
lib.write(name, item, metadata=metadata)
|
|
112
120
|
|
|
113
121
|
def _get_item(self, libname: str, name: str) -> Union[FrameorSeriesUnion, Dict]:
|
|
114
|
-
"""
|
|
122
|
+
"""Retrieve item from library (internal method).
|
|
115
123
|
|
|
116
124
|
Parameters
|
|
117
125
|
----------
|
|
@@ -129,7 +137,7 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
129
137
|
return lib.read(name).data
|
|
130
138
|
|
|
131
139
|
def _del_item(self, libname: str, name: str) -> None:
|
|
132
|
-
"""
|
|
140
|
+
"""Delete items (series or models) (internal method).
|
|
133
141
|
|
|
134
142
|
Parameters
|
|
135
143
|
----------
|
|
@@ -142,7 +150,7 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
142
150
|
lib.delete(name)
|
|
143
151
|
|
|
144
152
|
def _get_metadata(self, libname: str, name: str) -> dict:
|
|
145
|
-
"""
|
|
153
|
+
"""Retrieve metadata for an item (internal method).
|
|
146
154
|
|
|
147
155
|
Parameters
|
|
148
156
|
----------
|
|
@@ -199,6 +207,8 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
199
207
|
|
|
200
208
|
|
|
201
209
|
class ArcticDBConnector(BaseConnector, ConnectorUtil):
|
|
210
|
+
"""ArcticDBConnector object using ArcticDB to store data."""
|
|
211
|
+
|
|
202
212
|
conn_type = "arcticdb"
|
|
203
213
|
|
|
204
214
|
def __init__(self, name: str, uri: str):
|
|
@@ -228,8 +238,7 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
|
|
|
228
238
|
self._update_all_oseries_model_links()
|
|
229
239
|
|
|
230
240
|
def _initialize(self) -> None:
|
|
231
|
-
"""
|
|
232
|
-
|
|
241
|
+
"""Initialize the libraries (internal method)."""
|
|
233
242
|
for libname in self._default_library_names:
|
|
234
243
|
if self._library_name(libname) not in self.arc.list_libraries():
|
|
235
244
|
self.arc.create_library(self._library_name(libname))
|
|
@@ -242,7 +251,7 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
|
|
|
242
251
|
self.libs[libname] = self._get_library(libname)
|
|
243
252
|
|
|
244
253
|
def _library_name(self, libname: str) -> str:
|
|
245
|
-
"""
|
|
254
|
+
"""Get full library name according to ArcticDB (internal method)."""
|
|
246
255
|
return ".".join([self.name, libname])
|
|
247
256
|
|
|
248
257
|
def _get_library(self, libname: str):
|
|
@@ -270,7 +279,7 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
|
|
|
270
279
|
metadata: Optional[Dict] = None,
|
|
271
280
|
**_,
|
|
272
281
|
) -> None:
|
|
273
|
-
"""
|
|
282
|
+
"""Add item to library (time series or model) (internal method).
|
|
274
283
|
|
|
275
284
|
Parameters
|
|
276
285
|
----------
|
|
@@ -292,7 +301,7 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
|
|
|
292
301
|
lib.write(name, item, metadata=metadata)
|
|
293
302
|
|
|
294
303
|
def _get_item(self, libname: str, name: str) -> Union[FrameorSeriesUnion, Dict]:
|
|
295
|
-
"""
|
|
304
|
+
"""Retrieve item from library (internal method).
|
|
296
305
|
|
|
297
306
|
Parameters
|
|
298
307
|
----------
|
|
@@ -310,7 +319,7 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
|
|
|
310
319
|
return lib.read(name).data
|
|
311
320
|
|
|
312
321
|
def _del_item(self, libname: str, name: str) -> None:
|
|
313
|
-
"""
|
|
322
|
+
"""Delete items (series or models) (internal method).
|
|
314
323
|
|
|
315
324
|
Parameters
|
|
316
325
|
----------
|
|
@@ -323,7 +332,7 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
|
|
|
323
332
|
lib.delete(name)
|
|
324
333
|
|
|
325
334
|
def _get_metadata(self, libname: str, name: str) -> dict:
|
|
326
|
-
"""
|
|
335
|
+
"""Retrieve metadata for an item (internal method).
|
|
327
336
|
|
|
328
337
|
Parameters
|
|
329
338
|
----------
|
|
@@ -380,6 +389,8 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
|
|
|
380
389
|
|
|
381
390
|
|
|
382
391
|
class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
392
|
+
"""PystoreConnector object using pystore as database backend."""
|
|
393
|
+
|
|
383
394
|
conn_type = "pystore"
|
|
384
395
|
|
|
385
396
|
def __init__(self, name: str, path: str):
|
|
@@ -392,6 +403,12 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
392
403
|
path : str
|
|
393
404
|
path to the pystore directory
|
|
394
405
|
"""
|
|
406
|
+
warnings.warn(
|
|
407
|
+
"PystoreConnector is deprecated. Please use a different "
|
|
408
|
+
"connector, e.g. `pst.PasConnector`.",
|
|
409
|
+
DeprecationWarning,
|
|
410
|
+
stacklevel=1,
|
|
411
|
+
)
|
|
395
412
|
try:
|
|
396
413
|
import pystore
|
|
397
414
|
except ModuleNotFoundError as e:
|
|
@@ -412,7 +429,7 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
412
429
|
self._update_all_oseries_model_links()
|
|
413
430
|
|
|
414
431
|
def _initialize(self) -> None:
|
|
415
|
-
"""
|
|
432
|
+
"""Initialize the libraries (stores) (internal method)."""
|
|
416
433
|
for libname in self._default_library_names:
|
|
417
434
|
if libname in self.store.list_collections():
|
|
418
435
|
print(
|
|
@@ -447,7 +464,7 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
447
464
|
metadata: Optional[Dict] = None,
|
|
448
465
|
overwrite: bool = False,
|
|
449
466
|
) -> None:
|
|
450
|
-
"""
|
|
467
|
+
"""Add item to library (time series or model) (internal method).
|
|
451
468
|
|
|
452
469
|
Parameters
|
|
453
470
|
----------
|
|
@@ -489,7 +506,7 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
489
506
|
lib.write(name, s, metadata=metadata, overwrite=overwrite)
|
|
490
507
|
|
|
491
508
|
def _get_item(self, libname: str, name: str) -> Union[FrameorSeriesUnion, Dict]:
|
|
492
|
-
"""
|
|
509
|
+
"""Retrieve item from pystore library (internal method).
|
|
493
510
|
|
|
494
511
|
Parameters
|
|
495
512
|
----------
|
|
@@ -522,7 +539,7 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
522
539
|
return s
|
|
523
540
|
|
|
524
541
|
def _del_item(self, libname: str, name: str) -> None:
|
|
525
|
-
"""
|
|
542
|
+
"""Delete data from the store (internal method).
|
|
526
543
|
|
|
527
544
|
Parameters
|
|
528
545
|
----------
|
|
@@ -536,7 +553,7 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
536
553
|
self._clear_cache(libname)
|
|
537
554
|
|
|
538
555
|
def _get_metadata(self, libname: str, name: str) -> dict:
|
|
539
|
-
"""
|
|
556
|
+
"""Read metadata from pystore (internal method).
|
|
540
557
|
|
|
541
558
|
Parameters
|
|
542
559
|
----------
|
|
@@ -600,6 +617,8 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
|
|
|
600
617
|
|
|
601
618
|
|
|
602
619
|
class DictConnector(BaseConnector, ConnectorUtil):
|
|
620
|
+
"""DictConnector object that stores timeseries and models in dictionaries."""
|
|
621
|
+
|
|
603
622
|
conn_type = "dict"
|
|
604
623
|
|
|
605
624
|
def __init__(self, name: str = "pastas_db"):
|
|
@@ -643,7 +662,7 @@ class DictConnector(BaseConnector, ConnectorUtil):
|
|
|
643
662
|
metadata: Optional[Dict] = None,
|
|
644
663
|
**_,
|
|
645
664
|
) -> None:
|
|
646
|
-
"""
|
|
665
|
+
"""Add item (time series or models) (internal method).
|
|
647
666
|
|
|
648
667
|
Parameters
|
|
649
668
|
----------
|
|
@@ -663,7 +682,7 @@ class DictConnector(BaseConnector, ConnectorUtil):
|
|
|
663
682
|
lib[name] = (metadata, item)
|
|
664
683
|
|
|
665
684
|
def _get_item(self, libname: str, name: str) -> Union[FrameorSeriesUnion, Dict]:
|
|
666
|
-
"""
|
|
685
|
+
"""Retrieve item from database (internal method).
|
|
667
686
|
|
|
668
687
|
Parameters
|
|
669
688
|
----------
|
|
@@ -685,7 +704,7 @@ class DictConnector(BaseConnector, ConnectorUtil):
|
|
|
685
704
|
return item
|
|
686
705
|
|
|
687
706
|
def _del_item(self, libname: str, name: str) -> None:
|
|
688
|
-
"""
|
|
707
|
+
"""Delete items (series or models) (internal method).
|
|
689
708
|
|
|
690
709
|
Parameters
|
|
691
710
|
----------
|
|
@@ -698,7 +717,7 @@ class DictConnector(BaseConnector, ConnectorUtil):
|
|
|
698
717
|
_ = lib.pop(name)
|
|
699
718
|
|
|
700
719
|
def _get_metadata(self, libname: str, name: str) -> dict:
|
|
701
|
-
"""
|
|
720
|
+
"""Read metadata (internal method).
|
|
702
721
|
|
|
703
722
|
Parameters
|
|
704
723
|
----------
|
|
@@ -742,6 +761,8 @@ class DictConnector(BaseConnector, ConnectorUtil):
|
|
|
742
761
|
|
|
743
762
|
|
|
744
763
|
class PasConnector(BaseConnector, ConnectorUtil):
|
|
764
|
+
"""PasConnector object that stores time series and models as JSON files on disk."""
|
|
765
|
+
|
|
745
766
|
conn_type = "pas"
|
|
746
767
|
|
|
747
768
|
def __init__(self, name: str, path: str):
|
|
@@ -767,7 +788,7 @@ class PasConnector(BaseConnector, ConnectorUtil):
|
|
|
767
788
|
self._update_all_oseries_model_links()
|
|
768
789
|
|
|
769
790
|
def _initialize(self) -> None:
|
|
770
|
-
"""
|
|
791
|
+
"""Initialize the libraries (internal method)."""
|
|
771
792
|
for val in self._default_library_names:
|
|
772
793
|
libdir = os.path.join(self.path, val)
|
|
773
794
|
if not os.path.exists(libdir):
|
|
@@ -803,7 +824,7 @@ class PasConnector(BaseConnector, ConnectorUtil):
|
|
|
803
824
|
metadata: Optional[Dict] = None,
|
|
804
825
|
**_,
|
|
805
826
|
) -> None:
|
|
806
|
-
"""
|
|
827
|
+
"""Add item (time series or models) (internal method).
|
|
807
828
|
|
|
808
829
|
Parameters
|
|
809
830
|
----------
|
|
@@ -845,7 +866,7 @@ class PasConnector(BaseConnector, ConnectorUtil):
|
|
|
845
866
|
fm.write(jsondict)
|
|
846
867
|
|
|
847
868
|
def _get_item(self, libname: str, name: str) -> Union[FrameorSeriesUnion, Dict]:
|
|
848
|
-
"""
|
|
869
|
+
"""Retrieve item (internal method).
|
|
849
870
|
|
|
850
871
|
Parameters
|
|
851
872
|
----------
|
|
@@ -878,7 +899,7 @@ class PasConnector(BaseConnector, ConnectorUtil):
|
|
|
878
899
|
return item
|
|
879
900
|
|
|
880
901
|
def _del_item(self, libname: str, name: str) -> None:
|
|
881
|
-
"""
|
|
902
|
+
"""Delete items (series or models) (internal method).
|
|
882
903
|
|
|
883
904
|
Parameters
|
|
884
905
|
----------
|
|
@@ -898,7 +919,7 @@ class PasConnector(BaseConnector, ConnectorUtil):
|
|
|
898
919
|
pass
|
|
899
920
|
|
|
900
921
|
def _get_metadata(self, libname: str, name: str) -> dict:
|
|
901
|
-
"""
|
|
922
|
+
"""Read metadata (internal method).
|
|
902
923
|
|
|
903
924
|
Parameters
|
|
904
925
|
----------
|
pastastore/datasets.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"""Module containing example dataset."""
|
|
2
|
+
|
|
1
3
|
import os
|
|
2
4
|
|
|
3
5
|
import pandas as pd
|
|
@@ -13,7 +15,7 @@ from pastastore.base import BaseConnector
|
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
def example_pastastore(conn="DictConnector"):
|
|
16
|
-
"""
|
|
18
|
+
"""Get example PastaStore.
|
|
17
19
|
|
|
18
20
|
Parameters
|
|
19
21
|
----------
|
|
@@ -27,7 +29,6 @@ def example_pastastore(conn="DictConnector"):
|
|
|
27
29
|
pstore : pastastore.PastaStore
|
|
28
30
|
PastaStore containing example dataset
|
|
29
31
|
"""
|
|
30
|
-
|
|
31
32
|
# check it test dataset is available
|
|
32
33
|
datadir = os.path.join(os.path.dirname(__file__), "../tests/data")
|
|
33
34
|
if not os.path.exists(datadir):
|