Skip to content

Make data saver accept numpy type floats/ints #1225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 15, 2018
16 changes: 13 additions & 3 deletions qcodes/dataset/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from time import monotonic
from collections import OrderedDict
from typing import (Callable, Union, Dict, Tuple, List, Sequence, cast,
MutableMapping, MutableSequence, Optional)
MutableMapping, MutableSequence, Optional, Any)
from inspect import signature
from numbers import Number

Expand All @@ -19,13 +19,23 @@
log = logging.getLogger(__name__)

array_like_types = (tuple, list, np.ndarray)
non_array_like_types = (int, float, str)


class ParameterTypeError(Exception):
pass


def is_number(thing: Any) -> bool:
"""
Test if an object can be converted to a number
"""
try:
float(thing)
return True
except (ValueError, TypeError):
return False


class DataSaver:
"""
The class used byt the Runner context manager to handle the
Expand Down Expand Up @@ -114,7 +124,7 @@ def add_result(self,
f'and {array_size}')
else:
input_size = array_size
elif any(isinstance(value, t) for t in non_array_like_types):
elif is_number(value) or isinstance(value, str):
pass
else:
raise ValueError('Wrong value type received. '
Expand Down