Skip to content

Commit 23b659c

Browse files
committed
Simplify dtype/length code
1 parent e4b5cb4 commit 23b659c

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

hapiclient/hapi.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -803,26 +803,17 @@ def compute_dt(meta, opts):
803803
if ptype == 'integer':
804804
dtype = (pnames[i], np.dtype('<i4'), psizes[i])
805805

806-
if opts['format'] == 'binary':
807-
# TODO: If 'length' not available, warn and fall back to CSV.
808-
# Technically, server response is invalid in this case b/c length attribute
809-
# required for all parameters if format=binary.
810-
if ptype == 'string' or ptype == 'isotime':
811-
dtype = (pnames[i], 'S' + str(meta["parameters"][i]["length"]), psizes[i])
812-
else:
813-
# When format=csv, length attribute may not be given (but must be given for
814-
# first parameter according to the HAPI spec).
815-
if ptype == 'string' or ptype == 'isotime':
816-
if 'length' in meta["parameters"][i]:
817-
# length is specified for parameter in metadata. Use it.
818-
if ptype == 'string' or 'isotime':
819-
dtype = (pnames[i], 'S' + str(meta["parameters"][i]["length"]), psizes[i])
820-
else:
821-
# A string or isotime parameter did not have a length.
822-
# Will need to use slower CSV read method.
823-
missing_length = True
824-
if ptype == 'string' or ptype == 'isotime':
825-
dtype = (pnames[i], object, psizes[i])
806+
if ptype == 'string' or ptype == 'isotime':
807+
if 'length' in meta["parameters"][i]:
808+
# length is specified for parameter in metadata. Use it.
809+
if ptype == 'string' or 'isotime':
810+
dtype = (pnames[i], 'S' + str(meta["parameters"][i]["length"]), psizes[i])
811+
else:
812+
# A string or isotime parameter did not have a length.
813+
# Will need to use slower CSV read method.
814+
missing_length = True
815+
if ptype == 'string' or ptype == 'isotime':
816+
dtype = (pnames[i], object, psizes[i])
826817

827818
# For testing reader. Force use of slow read method.
828819
if opts['format'] == 'csv':

0 commit comments

Comments
 (0)