Skip to content

Commit 88fa1eb

Browse files
committed
support for h5py and json readers and writers
1 parent 825fc89 commit 88fa1eb

21 files changed

+429
-273
lines changed

data/hdf5/dset_creationprop.h5

-830 Bytes
Binary file not shown.

data/json/nullspace_dset.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

setup.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
max-line-length = 120
3+
# E402: module level import not at top of file
4+
# C901: too complex
5+
# F401: unused exports are necessary in __init__.py
6+
ignore = E402, C901, F401

src/h5json/array_util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ def arrayToBytes(arr, encoding=None):
491491
data = encodeData(data)
492492
return data
493493

494+
494495
def bytesToArray(data, dt, shape, encoding=None):
495496
"""
496497
Create numpy array based on byte representation
@@ -522,7 +523,7 @@ def bytesToArray(data, dt, shape, encoding=None):
522523

523524
return arr
524525

525-
526+
526527
def getNumpyValue(value, dt=None, encoding=None):
527528
"""
528529
Return value as numpy type for given dtype and encoding

src/h5json/dset_util.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,31 @@
1212

1313
import time
1414

15+
1516
def resize_dataset(dset_json, shape):
1617
shape_json = dset_json["shape"]
1718
shape_class = shape_json["class"]
1819
if shape_class != "H5S_SIMPLE":
1920
raise TypeError(f"dataset with shape class: {shape_class} cannot be resized")
20-
if len(shape_class["dims"]) != len(shape):
21+
if len(shape_json["dims"]) != len(shape):
2122
raise ValueError("Resize shape parameter doesn't match dataset's rank")
23+
if "maxdims" not in shape_json:
24+
raise ValueError("Dataset is not resizable")
25+
dims = shape_json["dims"]
26+
maxdims = shape_json["maxdims"]
27+
2228
if shape_json["dims"] == list(shape):
2329
# no change, just return
2430
return
31+
for i in range(len(dims)):
32+
extent = shape[i]
33+
if extent < 0:
34+
raise ValueError("dimensions can't be negative")
35+
if maxdims[i] == "H5S_UNLIMITED":
36+
# any positive extent is ok
37+
continue
38+
if extent > maxdims[i]:
39+
raise ValueError(f"extent for dimension {i} can't be larger than {maxdims[i]}")
40+
2541
shape_json["dims"] = list(shape)
2642
dset_json["modified"] = time.time()
27-
28-

src/h5json/filters.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# distribution tree. If you do not have access to this file, you may #
1010
# request a copy from help@hdfgroup.org. #
1111
##############################################################################
12-
12+
1313
import h5py
1414

1515
_HDF_FILTERS = {
@@ -53,4 +53,3 @@
5353
}
5454

5555
_H5PY_COMPRESSION_FILTERS = ("gzip", "lzf", "szip")
56-

src/h5json/h5py_util.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515

1616
from . import hdf5dtype
1717

18+
1819
def is_reference(val):
1920
""" Return True if the type or value is a Reference """
2021

2122
if isinstance(val, object) and val.__class__.__name__ == "Reference":
2223
return True
2324
elif isinstance(val, type) and val.__name__ == "Reference":
2425
return True
25-
26-
return False
26+
else:
27+
return False
2728

2829

2930
def is_regionreference(val):
@@ -59,7 +60,7 @@ def has_reference(dtype):
5960

6061
def convert_dtype(srcdt, to_h5py=True):
6162
"""Return a dtype based on input dtype, converting any Reference types from
62-
h5py style to h5pyd and vice-versa.
63+
h5py style to h5json and vice-versa.
6364
"""
6465

6566
if len(srcdt) > 0:
@@ -96,7 +97,7 @@ def convert_dtype(srcdt, to_h5py=True):
9697
if to_h5py:
9798
tgt_dt = h5py.special_dtype(vlen=tgt_base)
9899
else:
99-
tgt_dt = h5pyd.special_dtype(vlen=tgt_base)
100+
tgt_dt = hdf5dtype.special_dtype(vlen=tgt_base)
100101
elif srcdt.kind == "U":
101102
# use vlen for unicode strings
102103
if to_h5py:

0 commit comments

Comments
 (0)