datastock 0.0.42__py3-none-any.whl → 0.0.43__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.
datastock/_class0.py CHANGED
@@ -161,11 +161,13 @@ class DataStock0(object):
161
161
 
162
162
  def save(
163
163
  self,
164
+ pfe=None,
164
165
  path=None,
165
166
  name=None,
166
167
  sep=None,
167
- verb=True,
168
+ overwrite=None,
168
169
  return_pfe=False,
170
+ verb=True,
169
171
  ):
170
172
 
171
173
  lsep = [';', '&', '?', '#', ',', '~', '.', '-', '_']
@@ -191,9 +193,11 @@ class DataStock0(object):
191
193
  asarray=True,
192
194
  returnas='blended',
193
195
  ),
196
+ pfe=pfe,
194
197
  sep=sep,
195
198
  path=path,
196
199
  name=name,
200
+ overwrite=overwrite,
197
201
  clsname=self.__class__.__name__,
198
202
  return_pfe=return_pfe,
199
203
  verb=verb,
datastock/_saveload.py CHANGED
@@ -26,10 +26,12 @@ _KEY_SEP = '--sep--'
26
26
 
27
27
  def save(
28
28
  dflat=None,
29
+ pfe=None,
29
30
  sep=None,
30
31
  name=None,
31
32
  path=None,
32
33
  clsname=None,
34
+ overwrite=None,
33
35
  return_pfe=None,
34
36
  verb=None,
35
37
  ):
@@ -37,30 +39,97 @@ def save(
37
39
 
38
40
  # ------------
39
41
  # check inputs
42
+ # ------------
40
43
 
41
- # path
42
- path = _generic_check._check_var(
43
- path, 'path',
44
- default=os.path.abspath('./'),
45
- types=str,
46
- )
47
- path = os.path.abspath(path)
48
- if not os.path.isdir(path):
49
- msg = f"Arg path must be a valid path!\nProvided: {path}"
44
+ # ------------------
45
+ # pfe vs path/name
46
+
47
+ lc = [
48
+ pfe is not None,
49
+ path is not None or name is not None,
50
+ ]
51
+
52
+ if np.sum(lc) > 1:
53
+ msg = (
54
+ "Saving, please provide {pfe} xor {path and/or name}!\n"
55
+ f"\t- path: {path}\n"
56
+ f"\t- name: {name}\n"
57
+ f"\t- pfe: {pfe}\n"
58
+ )
50
59
  raise Exception(msg)
51
60
 
52
- # clsname
53
- clsname = _generic_check._check_var(
54
- clsname, 'clsname',
55
- default='DataCollection',
56
- types=str,
57
- )
61
+ # ------------------
62
+ # pfe vs path/name
63
+
64
+ if lc[0]:
65
+ if not isinstance(pfe, str):
66
+ msg = (
67
+ "Arg pfe must be a str ponting to a file!\n"
68
+ f"Provided: {pfe}\n"
69
+ )
70
+ raise Exception(msg)
58
71
 
59
- # name
60
- name = _generic_check._check_var(
61
- name, 'name',
62
- default='name',
63
- types=str,
72
+ sdir, sfile = os.path.split(pfe)
73
+ if sdir == '':
74
+ sdir = os.path.asbpath('.')
75
+
76
+ # check path
77
+ if not os.path.isdir(sdir):
78
+ msg = (
79
+ "Arg pfe seems to have a non-valid path!\n"
80
+ "Provided: {sdir}\n"
81
+ )
82
+ raise Exception(msg)
83
+
84
+ # check file name
85
+ if not sfile.endswith('.npz'):
86
+ sfile = f"{sfile}.npz"
87
+
88
+ # re-assemble
89
+ pfe = os.path.join(sdir, sfile)
90
+
91
+ else:
92
+ # path
93
+ path = _generic_check._check_var(
94
+ path, 'path',
95
+ default=os.path.abspath('./'),
96
+ types=str,
97
+ )
98
+ path = os.path.abspath(path)
99
+ if not os.path.isdir(path):
100
+ msg = f"Arg path must be a valid path!\nProvided: {path}"
101
+ raise Exception(msg)
102
+
103
+ # clsname
104
+ clsname = _generic_check._check_var(
105
+ clsname, 'clsname',
106
+ default='DataCollection',
107
+ types=str,
108
+ )
109
+
110
+ # name
111
+ name = _generic_check._check_var(
112
+ name, 'name',
113
+ default='name',
114
+ types=str,
115
+ )
116
+
117
+ # set automatic name
118
+ user = getpass.getuser()
119
+ dt = dtm.datetime.now().strftime("%Y%m%d-%H%M%S")
120
+ name = f'{clsname}_{name}_{user}_{dt}.npz'
121
+
122
+ # pfe
123
+ pfe = os.path.join(path, name)
124
+
125
+ # ------------------
126
+ # options
127
+
128
+ # overwrite
129
+ overwrite = _generic_check._check_var(
130
+ overwrite, 'overwrite',
131
+ default=False,
132
+ types=bool,
64
133
  )
65
134
 
66
135
  # verb
@@ -79,24 +148,44 @@ def save(
79
148
 
80
149
  # ----------------------
81
150
  # save / print / return
82
-
83
- user = getpass.getuser()
84
- dt = dtm.datetime.now().strftime("%Y%m%d-%H%M%S")
85
- name = f'{clsname}_{name}_{user}_{dt}.npz'
151
+ # ----------------------
86
152
 
87
153
  # add sep
88
154
  dflat[_KEY_SEP] = sep
89
155
 
156
+ # -----------------
157
+ # check vs existing
158
+
159
+ if os.path.isfile(pfe):
160
+ if overwrite is True:
161
+ msg = (
162
+ "Overwriting existing file:\n"
163
+ f"\t{pfe}"
164
+ )
165
+ warnings.warn(msg)
166
+ else:
167
+ msg = (
168
+ "File already existing!\n"
169
+ "\t=> use overwrite = True to overwrite\n"
170
+ f"\t{pfe}"
171
+ )
172
+ raise Exception(msg)
173
+
174
+ # --------
90
175
  # save
91
- pfe = os.path.join(path, name)
92
- np.savez(pfe, **dflat)
93
176
 
177
+ np.savez(pfe, **dflat)
178
+
179
+ # -------
94
180
  # print
181
+
95
182
  if verb:
96
- msg = f"Saved in:\n\t{pfe}"
183
+ msg = f"\nSaved in:\n\t{pfe}\n"
97
184
  print(msg)
98
185
 
186
+ # -------
99
187
  # return
188
+
100
189
  if return_pfe is True:
101
190
  return pfe
102
191
 
@@ -602,7 +602,12 @@ class Test02_Manipulate():
602
602
  def test22_get_nbytes(self):
603
603
  nb, dnb = self.st.get_nbytes()
604
604
 
605
- def test23_saveload(self, verb=False):
605
+ def test23_save_pfe(self, verb=False):
606
+ pfe = os.path.join(_PATH_OUTPUT, 'testsave.npz')
607
+ self.st.save(pfe=pfe, return_pfe=False)
608
+ os.remove(pfe)
609
+
610
+ def test24_saveload(self, verb=False):
606
611
  pfe = self.st.save(path=_PATH_OUTPUT, verb=verb, return_pfe=True)
607
612
  st2 = load(pfe, verb=verb)
608
613
  # Just to check the loaded version works fine
datastock/version.py CHANGED
@@ -1,2 +1,2 @@
1
1
  # Do not edit, pipeline versioning governed by git tags!
2
- __version__ = '0.0.42'
2
+ __version__ = '0.0.43'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: datastock
3
- Version: 0.0.42
3
+ Version: 0.0.43
4
4
  Summary: A python library for generic class and data handling
5
5
  Home-page: https://github.com/ToFuProject/datastock
6
6
  Author: Didier VEZINET
@@ -2,7 +2,7 @@ _updateversion.py,sha256=OR6OJJozaHWzu7NWjKu5ERi0IyYqR61KrWvzf7kfoto,951
2
2
  datastock/_DataCollection_utils.py,sha256=hHf6HvGKMmM-psx3fj9QcY1TEmKrAtTdkRokH7SFqoo,7143
3
3
  datastock/__init__.py,sha256=i_Ijl-AM07n4zN52frWfbeGN1iB6v4e5oLzTuVIh_oM,217
4
4
  datastock/_class.py,sha256=Az9PS3aSskiPMb1ekt78Y2ynBujYVc_cDjJxW9xH9g4,47
5
- datastock/_class0.py,sha256=2mju4Larmj1Sv5ZMuqPTLvCY-BajhGD3qG6QBalTnRY,5893
5
+ datastock/_class0.py,sha256=r4I5BvFZsXMWdkWczpUMC65sqr1rf4BV2Aa8i3NYOGE,5989
6
6
  datastock/_class1.py,sha256=8R4zM6p7b62FJuoI7Gyik4_tRCUFi6aF4oaMimiOoFE,28726
7
7
  datastock/_class1_binning.py,sha256=LWHv2LIfgZfSFWYwqdcN0DKpNe6q7Go3sxfcJqmzTrI,28085
8
8
  datastock/_class1_check.py,sha256=0azV7ftoAWsqTMEYbGQ_luJi95Px-pBif_vOug3W8Zg,50978
@@ -30,13 +30,13 @@ datastock/_plot_as_profile1d.py,sha256=ebOrzcV1m197Ua1CE04EV6mno_LryrumCpwGcrrDZ
30
30
  datastock/_plot_correlations.py,sha256=ITOypu_AEoKl0ihxocV-JVTXIHqut6p9TfG-xZmQysc,10175
31
31
  datastock/_plot_old_backup.py,sha256=XixTi2CiihKjtQP0TRycH0b25caWN1m35DgpsDeiWZE,21729
32
32
  datastock/_plot_text.py,sha256=wQPqjfpLyIioS2JeOt3E9C9HgYUJ49YEoOgRuKYvAR8,3143
33
- datastock/_saveload.py,sha256=NdOykvmeCaPhpk0EF5WQezYzpuZM2Ul101Nqc4I3dnY,11729
34
- datastock/version.py,sha256=eImSu2FfqgzmD49HEFW5QfRn9NBAw_itX40-C-Zj7V0,80
33
+ datastock/_saveload.py,sha256=Ri6VswZTRBtYWFQfzWYGJQrOgrTJZRHr9TRVVkamG7w,13799
34
+ datastock/version.py,sha256=_VXLMCwW1rohyixPEKPXfzkca_I3iiPiriaNUy7zF4w,80
35
35
  datastock/tests/__init__.py,sha256=teOo2xP0IO7PQMuMDmum61XVHe2TuxW3BiHiL73X8jQ,35
36
- datastock/tests/test_01_DataStock.py,sha256=QJSmrVXD6wX-plfrFdLyZou20IYZGAKzartSi84BfC0,16982
36
+ datastock/tests/test_01_DataStock.py,sha256=ZeKgVwQ78xSyO_Mv6HTU1dbzcxixhNDVgm9-BteX7oM,17154
37
37
  datastock/tests/output/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
38
- datastock-0.0.42.dist-info/LICENSE,sha256=V1uXqi3vxR0QhB4QdFyjkynl6jpN4wZmlB5EMYJk0NM,1068
39
- datastock-0.0.42.dist-info/METADATA,sha256=VaEXXEm0YfQQmm_ccn37rA13jkzppnLnTJdfc0oi6qQ,8660
40
- datastock-0.0.42.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
41
- datastock-0.0.42.dist-info/top_level.txt,sha256=BzJsLLK_zZw13WQCoMhC74qWVKalnVCjBxdPXvJn7HQ,25
42
- datastock-0.0.42.dist-info/RECORD,,
38
+ datastock-0.0.43.dist-info/LICENSE,sha256=V1uXqi3vxR0QhB4QdFyjkynl6jpN4wZmlB5EMYJk0NM,1068
39
+ datastock-0.0.43.dist-info/METADATA,sha256=WDcIGRyBy1Ccel7wavSpAJt368B35W_eQBPxAyBnG_Y,8660
40
+ datastock-0.0.43.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
41
+ datastock-0.0.43.dist-info/top_level.txt,sha256=BzJsLLK_zZw13WQCoMhC74qWVKalnVCjBxdPXvJn7HQ,25
42
+ datastock-0.0.43.dist-info/RECORD,,