Skip to content

Commit 8eccb42

Browse files
committed
h5py optional dependency
1 parent 2bed1e7 commit 8eccb42

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

docs/install.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Installing using pip or conda will automatically install or update these core
5353
dependencies if necessary. SkyPy also has a number of optional dependencies
5454
that enable additional features:
5555

56+
- `h5py <https://www.h5py.org/>`_
5657
- `speclite <https://speclite.readthedocs.io/>`_
5758

5859
To install SkyPy with all optional dependencies using pip:

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ test =
3333
pytest-rerunfailures
3434
speclite>=0.11
3535
all =
36+
h5py
3637
speclite>=0.11
3738
docs =
3839
sphinx-astropy

skypy/pipeline/tests/test_pipeline.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
from skypy.pipeline import Pipeline
1414
from skypy.pipeline._items import Call, Ref
1515

16+
try:
17+
import h5py # noqa
18+
except ImportError:
19+
HAS_H5PY = False
20+
else:
21+
HAS_H5PY = True
22+
1623

1724
def test_pipeline():
1825

@@ -44,13 +51,7 @@ def test_pipeline():
4451
with fits.open(output_filename) as hdu:
4552
assert np.all(Table(hdu['test_table'].data) == pipeline['test_table'])
4653

47-
# Test hdf5
48-
hdf5_filename = 'output.hdf5'
49-
pipeline.write(hdf5_filename)
50-
hdf5_table = read_table_hdf5(hdf5_filename, 'tables/test_table', character_as_bytes=False)
51-
assert np.all(hdf5_table == pipeline['test_table'])
52-
53-
# Test invalid extensions
54+
# Test invalid file extension
5455
with pytest.raises(ValueError):
5556
pipeline.write('output.invalid')
5657

@@ -249,8 +250,30 @@ def value_in_cm(q):
249250
np.testing.assert_array_less(pipeline['test_table.lengths_in_cm'], 100)
250251

251252

253+
@pytest.mark.skipif(not HAS_H5PY, reason='Requires h5py')
254+
def test_hdf5():
255+
size = 100
256+
string = size*'a'
257+
config = {'tables': {
258+
'test_table': {
259+
'column1': Call(np.random.uniform, [], {
260+
'size': size}),
261+
'column2': Call(np.random.uniform, [], {
262+
'low': Ref('test_table.column1')}),
263+
'column3': Call(list, [string], {})}}}
264+
265+
pipeline = Pipeline(config)
266+
pipeline.execute()
267+
pipeline.write('output.hdf5')
268+
hdf_table = read_table_hdf5('output.hdf5', 'table/test_table', character_as_bytes=False)
269+
assert np.all(hdf_table == pipeline['test_table'])
270+
271+
252272
def teardown_module(module):
253273

254274
# Remove fits file generated in test_pipeline
255275
os.remove('output.fits')
256-
os.remove('output.hdf5')
276+
277+
# Remove hdf5 file generated in test_hdf5
278+
if HAS_H5PY:
279+
os.remove('output.hdf5')

0 commit comments

Comments
 (0)