Skip to content

Commit

Permalink
Sometimes labels can be bytes instead of str
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
  • Loading branch information
jeandet committed May 21, 2024
1 parent dd768bd commit be391f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions speasy/core/cdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def _fix_value_type(value):
return value
if type(value) is list:
return [_fix_value_type(sub_v) for sub_v in value]
if type(value) is bytes:
return value.decode('utf-8')
return str(value)


Expand All @@ -37,9 +39,9 @@ def _make_axis(axis, time_axis_name):

def _build_labels(variable: pyistp.loader.DataVariable):
if len(variable.values.shape) != 2:
return variable.labels
return _fix_value_type(variable.labels)
if type(variable.labels) is list and len(variable.labels) == variable.values.shape[1]:
return variable.labels
return _fix_value_type(variable.labels)
if type(variable.labels) is list and len(variable.labels) == 1:
return [f"{variable.labels[0]}[{i}]" for i in range(variable.values.shape[1])]
return [f"component_{i}" for i in range(variable.values.shape[1])]
Expand Down
6 changes: 6 additions & 0 deletions tests/test_cdaweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ def test_get_variable_ws(self, kw):
"variable": "pos_eq_op",
"start_time": datetime(2018, 1, 1, tzinfo=timezone.utc),
"stop_time": datetime(2018, 1, 1, 2, tzinfo=timezone.utc)
},
{
"dataset": "SOLO_L2_MAG-RTN-NORMAL-1-MINUTE",
"variable": "B_RTN",
"start_time": datetime(2021, 1, 1, tzinfo=timezone.utc),
"stop_time": datetime(2021, 1, 1, 2, tzinfo=timezone.utc)
}
)
def test_a_simple_direct_archive_request(self, kwargs):
Expand Down

0 comments on commit be391f2

Please sign in to comment.