Skip to content

Commit 03a7621

Browse files
authored
Merge pull request #680 from neutrinoceros/enh/dataset-from-path
ENH: add support for loading Dataset from a `pathlib.Path`
2 parents bc92149 + bdb4a85 commit 03a7621

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/vip_hci/config/utils_conf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from importlib.metadata import version
1616
from inspect import signature, Parameter
1717
from functools import wraps
18+
from pathlib import Path
1819
import multiprocessing
1920
import warnings
2021

@@ -69,10 +70,11 @@ def save(self, filename):
6970

7071
@classmethod
7172
def load(cls, filename):
73+
filename = Path(filename).resolve()
7274
try:
7375
data = np.load(filename, allow_pickle=True)
74-
except BaseException:
75-
data = np.load(filename + ".npz", allow_pickle=True)
76+
except FileNotFoundError:
77+
data = np.load(filename.with_suffix(".npz"), allow_pickle=True)
7678

7779
if "_vip_object" not in data:
7880
raise RuntimeError("The file you specified is not a VIP object.")

tests/pre_3_10/test_dataset.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
__author__ = "Ralf Farkas"
66

7-
import tempfile
87
import os
98
import sys
109

@@ -14,7 +13,7 @@
1413
from vip_hci.objects.dataset import Dataset
1514

1615

17-
def test_saveable_dataset():
16+
def test_saveable_dataset(tmp_path):
1817
"""
1918
Test the HCIDataset.save() and .load() methods
2019
"""
@@ -26,7 +25,7 @@ def test_saveable_dataset():
2625
ds = Dataset(cube=cube, angles=angles, fwhm=fwhm)
2726

2827
# save
29-
fd, fn = tempfile.mkstemp(prefix="vip_")
28+
fn = tmp_path / 'test'
3029
ds.save(fn)
3130

3231
# restore
@@ -36,6 +35,3 @@ def test_saveable_dataset():
3635
aarc(ds2.cube, cube)
3736
aarc(ds2.angles, angles)
3837
assert ds2.fwhm == fwhm
39-
40-
# cleanup
41-
os.remove(fn)

0 commit comments

Comments
 (0)