Skip to content

Commit 25c4cf3

Browse files
committed
fix dsetUtil flake errors
1 parent 7561534 commit 25c4cf3

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

hsds/util/dsetUtil.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from .. import hsds_logger as log
2020
from .. import config
2121

22-
#from .chunkUtil import getChunkSize, guessChunk, expandChunk, shrinkChunk
2322

2423
CHUNK_MIN = 512 * 1024 # Soft lower limit (512k)
2524
CHUNK_MAX = 2048 * 1024 # Hard upper limit (2M)
@@ -84,6 +83,7 @@
8483
"H5D_CONTIGUOUS_REF",
8584
)
8685

86+
8787
def get_dset_size(shape_json, typesize):
8888
"""Return the size of the dataspace. For
8989
any unlimited dimensions, assume a value of 1.
@@ -106,6 +106,7 @@ def get_dset_size(shape_json, typesize):
106106
dset_size *= shape[n]
107107
return dset_size
108108

109+
109110
def getFilterItem(key):
110111
"""
111112
Return filter code, id, and name, based on an id, a name or a code.
@@ -121,15 +122,15 @@ def getFilterItem(key):
121122

122123

123124
def getFiltersJson(create_props, supported_filters=None):
124-
""" return standardized filter representation from creation properties
125+
""" return standardized filter representation from creation properties
125126
raise bad request if invalid """
126-
127+
127128
# refer to https://hdf5-json.readthedocs.io/en/latest/bnf/\
128129
# filters.html#grammar-token-filter_list
129130

130131
if "filters" not in create_props:
131132
return {} # null set
132-
133+
133134
f_in = create_props["filters"]
134135

135136
log.debug(f"filters provided in creation_prop: {f_in}")
@@ -189,11 +190,11 @@ def getFiltersJson(create_props, supported_filters=None):
189190
msg = f"Unexpected type for filter: {filter}"
190191
log.warn(msg)
191192
raise HTTPBadRequest(reason=msg)
192-
193+
193194
# return standardized filter representation
194195
log.debug(f"using filters: {f_out}")
195196
return f_out
196-
197+
197198

198199
def getFilters(dset_json):
199200
"""Return list of filters, or empty list"""
@@ -298,7 +299,8 @@ def getFilterOps(app, dset_id, filters, dtype=None, chunk_shape=None):
298299
return filter_ops
299300
else:
300301
return None
301-
302+
303+
302304
def getShapeJson(body):
303305
""" Return normalized json description of data space """
304306

@@ -310,8 +312,8 @@ def getShapeJson(body):
310312
shape_class = "H5S_SCALAR"
311313
log.debug("not shape given - using H5S_SCALAR")
312314
return {"class": shape_class}
313-
314-
body_shape = body["shape"]
315+
316+
body_shape = body["shape"]
315317
log.debug(f"got shape: {body_shape}")
316318

317319
if isinstance(body_shape, int):
@@ -326,11 +328,11 @@ def getShapeJson(body):
326328
else:
327329
shape_class = "H5S_SIMPLE"
328330
dims = body_shape
329-
else:
331+
else:
330332
msg = "invalid shape: {body_shape}"
331333
log.warn(msg)
332334
raise ValueError(msg)
333-
335+
334336
if shape_class not in ("H5S_NULL", "H5S_SCALAR", "H5S_SIMPLE"):
335337
msg = f"invalid shape class: {shape_class}"
336338
log.warn(msg)
@@ -386,7 +388,7 @@ def getShapeJson(body):
386388
msg = "max_dims rank doesn't match dims"
387389
log.warn(msg)
388390
raise ValueError(msg)
389-
391+
390392
# return json description of shape
391393
shape_json = {"class": shape_class}
392394
if shape_class == "H5S_SIMPLE":
@@ -396,6 +398,7 @@ def getShapeJson(body):
396398
log.debug(f"returning shape_json: {shape_json}")
397399
return shape_json
398400

401+
399402
def getShapeClass(data_shape):
400403
""" Return shape class of the given data shape """
401404

@@ -404,11 +407,12 @@ def getShapeClass(data_shape):
404407

405408
if "class" not in data_shape:
406409
raise KeyError("expected 'class' key for data shape")\
407-
410+
408411
return data_shape["class"]
409412

413+
410414
def getRank(data_shape):
411-
""" Return rank of given data shape_json """
415+
""" Return rank of given data shape_json """
412416

413417
shape_class = getShapeClass(data_shape)
414418

@@ -423,6 +427,7 @@ def getRank(data_shape):
423427
else:
424428
raise ValueError(f"unexpected data shape class: {shape_class}")
425429

430+
426431
def getDsetRank(dset_json):
427432
"""Get rank returning 0 for scalar or NULL data shapes"""
428433
data_shape = dset_json["shape"]
@@ -445,7 +450,7 @@ def isScalarSpace(dset_json):
445450
shape_class = getShapeClass(data_shape)
446451
if shape_class == "H5S_NULL":
447452
return False
448-
453+
449454
rank = getRank(data_shape)
450455
return True if rank == 0 else False
451456

@@ -458,7 +463,7 @@ def getContiguousLayout(shape_json, item_size, chunk_min=None, chunk_max=None):
458463
msg = "ContiguousLayout can only be used with fixed-length types"
459464
log.warn(msg)
460465
raise ValueError(msg)
461-
466+
462467
if chunk_min is None:
463468
msg = "chunk_min not set"
464469
log.warn(msg)
@@ -470,7 +475,7 @@ def getContiguousLayout(shape_json, item_size, chunk_min=None, chunk_max=None):
470475

471476
if chunk_max < chunk_min:
472477
raise ValueError("chunk_max cannot be less than chunk_min")
473-
478+
474479
if shape_json is None or shape_json["class"] == "H5S_NULL":
475480
return None
476481
if shape_json["class"] == "H5S_SCALAR":
@@ -507,6 +512,7 @@ def getContiguousLayout(shape_json, item_size, chunk_min=None, chunk_max=None):
507512

508513
return layout
509514

515+
510516
def getChunkSize(layout, type_size):
511517
"""Return chunk size given layout.
512518
i.e. just the product of the values in the list.
@@ -521,6 +527,7 @@ def getChunkSize(layout, type_size):
521527
chunk_size *= n
522528
return chunk_size
523529

530+
524531
def validateChunkLayout(shape_json, item_size, layout, chunk_table=None):
525532
"""
526533
Use chunk layout given in the creationPropertiesList (if defined and
@@ -668,7 +675,7 @@ def validateChunkLayout(shape_json, item_size, layout, chunk_table=None):
668675
msg = f"Invalid chunk table id: {chunk_table_id}"
669676
log.warn(msg)
670677
raise HTTPBadRequest(reason=msg)
671-
678+
672679
elif layout_class == "H5D_CHUNKED":
673680
if "dims" not in layout:
674681
msg = "dims key not found in layout for creation property list"
@@ -695,7 +702,8 @@ def validateChunkLayout(shape_json, item_size, layout, chunk_table=None):
695702
msg = f"Unexpected layout: {layout_class}"
696703
log.warn(msg)
697704
raise ValueError(msg)
698-
705+
706+
699707
def expandChunk(layout, typesize, shape_json, chunk_min=CHUNK_MIN, layout_class="H5D_CHUNKED"):
700708
"""Compute an increased chunk shape with a size in bytes greater than chunk_min."""
701709
if shape_json is None or shape_json["class"] == "H5S_NULL":
@@ -833,7 +841,7 @@ def guessChunk(shape_json, typesize):
833841
def getLayoutJson(creation_props, shape=None, type_json=None, chunk_min=None, chunk_max=None):
834842
""" Get the layout json given by creation_props.
835843
Raise bad request error if invalid """
836-
844+
837845
min_chunk_size = int(config.get("min_chunk_size"))
838846
max_chunk_size = int(config.get("max_chunk_size"))
839847

@@ -853,7 +861,7 @@ def getLayoutJson(creation_props, shape=None, type_json=None, chunk_min=None, ch
853861
layout_props = creation_props["layout"]
854862
else:
855863
layout_props = None
856-
864+
857865
if layout_props:
858866
if "class" not in layout_props:
859867
msg = "expected class key in layout props"

0 commit comments

Comments
 (0)