JSON error passing numpy arrays to ocs client arg
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 19
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
This is happening when I pass a numpy array as a kwarg to pysmurf-controller's take_iv, e.g.
pysmurf_uv31 = matched_client.OCSClient('pysmurf-controller-s4', args=[])
bgs = np.arange(12)
pysmurf_uv31.take_iv.start(kwargs = {'bias_groups': bgs, 'overbias_wait': 1, 'bias_high': 20})
print( pysmurf_uv31.take_iv.wait() )
leads to this error:
Traceback (most recent call last):
File "test_pysmurf_iv.py", line 24, in <module>
pysmurf_uv31.take_iv.start(kwargs = iv_args)
File "/home/mcmlab/.local/lib/python3.8/site-packages/ocs/ocs_client.py", line 23, in start
return OCSReply(*client.request('start', name, params=kwargs))
File "/home/mcmlab/.local/lib/python3.8/site-packages/ocs/client_http.py", line 99, in request
return self.call(self.agent_addr + '.ops', action, op_name, params, **kw)
File "/home/mcmlab/.local/lib/python3.8/site-packages/ocs/client_http.py", line 26, in call
params = json.dumps({'procedure': procedure,
File "/usr/lib/python3.8/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python3.8/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ndarray is not JSON serializable
The script works if I pass it a list instead.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example with a NumPy array, then inspect ocs/client_http.py at the request path that calls json.dumps. Compare its handling of array kwargs with the existing list case and check whether regression coverage exists nearby. Done means the reported take_iv request no longer raises the JSON serialization error while list arguments continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100