Skip to content

Commit 7b82093

Browse files
committed
Fix for reading in old mesaplot v1 pickle files.
Add notes that people should not depend on this working between versions and for long term storage, history and profile files should be kept.
1 parent 45180cc commit 7b82093

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ m=mp.MESA()
5252

5353
Now m contains all the useful stuff
5454

55+
5556
### History files
5657
````python
5758
m.loadHistory()

mesaPlot/file_reader.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ def __getitem__(self, key):
204204
if key in self.data.dtype.names:
205205
return self.data[key]
206206
if key in self.head.dtype.names:
207-
return self.head[key][0]
207+
return np.atleast_1d(self.head[key])[0]
208+
208209

209210
try:
210211
return self.__dict__[key]
@@ -254,26 +255,35 @@ def _loadPickle(self, pickname, filename):
254255
# Get checksum
255256
filehash = _hash(filename)
256257
try:
257-
pickhash = pickle.load(f)
258-
except:
258+
version = pickle.load(f)
259+
except Exception:
259260
raise ValueError("Pickle file corrupted please delete it and try again")
260-
if len(str(pickhash)) == len(str(_PICKLE_VERSION)):
261-
if int(pickhash) != int(_PICKLE_VERSION):
262-
# Not a hash but a version number/ or wrong version number:
263-
return False
264261

265-
try:
262+
# For mesaplot 1.* this is a hash, while 2.* is a version number
263+
if len(str(version)) > 12:
264+
# Version 1.0 hash
265+
pickhash = version
266+
else:
267+
if int(version) != int(_PICKLE_VERSION):
268+
raise ValueError("Pickle file not recongised please delete it and try again")
269+
266270
pickhash = pickle.load(f)
267-
except TypeError:
268-
return False
269271

270272
if (
271273
os.path.exists(filename) and pickhash == filehash
272274
) or not os.path.exists(filename):
273275
# Data has not changed
274276
# Get Data
275-
self.data = pickle.load(f)
276-
self.head = pickle.load(f)
277+
data = pickle.load(f)
278+
279+
try:
280+
head = pickle.load(f)
281+
self.head = head
282+
self.data = data
283+
except EOFError: # Handle 1.* verisons of pickle files
284+
self.data = data.data
285+
self.head = data.head
286+
277287
self._loaded = True
278288
return True
279289
return False

0 commit comments

Comments
 (0)