Skip to content

Commit d87005a

Browse files
committed
Change the Reductionist API to return a JSON payload, ths removes all the headers such as x-activestorage-count in favour of returning their data as part of the JSON payload.
1 parent be78e13 commit d87005a

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

activestorage/reductionist.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,16 @@ def request(session: requests.Session, url: str, request_data: dict):
235235

236236
def decode_result(response):
237237
"""Decode a successful response, return as a 2-tuple of (numpy array or scalar, count)."""
238-
dtype = response.headers['x-activestorage-dtype']
239-
shape = json.loads(response.headers['x-activestorage-shape'])
238+
reduction_result = json.loads(response.content)
239+
dtype = reduction_result['dtype']
240+
shape = reduction_result['shape']
240241

241242
# Result
242-
result = np.frombuffer(response.content, dtype=dtype)
243+
result = np.frombuffer(bytes(reduction_result['bytes']), dtype=dtype)
243244
result = result.reshape(shape)
244245

245246
# Counts
246-
count = json.loads(response.headers['x-activestorage-count'])
247+
count = reduction_result['count']
247248
# TODO: When reductionist is ready, we need to fix 'count'
248249

249250
# Mask the result

tests/unit/test_reductionist.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111

1212

1313
def make_response(content, status_code, dtype=None, shape=None, count=None):
14-
response = requests.Response()
15-
response._content = content
16-
response.status_code = status_code
14+
reduction_result = {
15+
"bytes": content
16+
}
1717
if dtype:
18-
response.headers["x-activestorage-dtype"] = dtype
18+
reduction_result["dtype"] = dtype
1919
if shape:
20-
response.headers["x-activestorage-shape"] = shape
20+
reduction_result["shape"] = shape
2121
if count:
22-
response.headers["x-activestorage-count"] = count
22+
reduction_result["count"] = count
23+
response = requests.Response()
24+
response._content = json.dumps(reduction_result)
25+
response.status_code = status_code
2326
return response
2427

2528

0 commit comments

Comments
 (0)