Skip to content

Commit

Permalink
Merge pull request #817 from axsaucedo/multi_level_string
Browse files Browse the repository at this point in the history
Fixing multidimensional arrays being flattened
  • Loading branch information
ukclivecox authored Aug 26, 2019
2 parents fcd8b34 + 912ec26 commit 60c9fd2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/seldon_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def grpc_datadef_to_array(datadef: prediction_pb2.DefaultData) -> np.ndarray:
features = np.array(datadef.tensor.values).reshape(
datadef.tensor.shape)
elif data_type == "ndarray":
features = np.array(datadef.ndarray)
py_arr = json_format.MessageToDict(datadef.ndarray)
features = np.array(py_arr)
elif data_type == "tftensor":
features = tf.make_ndarray(datadef.tftensor)
else:
Expand Down
37 changes: 37 additions & 0 deletions python/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,43 @@ def test_create_grpc_reponse_nparray():
assert sm.data.WhichOneof("data_oneof") == "tensor"
assert sm.data.tensor.values == [1, 2, 3]

def test_create_rest_reponse_text_ndarray():
user_model = UserObject()
request_data = np.array([["hello", "world"], ["hello", "another", "world"]])
request = {
"data": {
"ndarray": request_data,
"names": []
}
}
(features, meta, datadef, data_type) = scu.extract_request_parts_json(request)
raw_response = np.array([["hello", "world"], ["here", "another"]])
result = scu.construct_response_json(
user_model,
True,
request,
raw_response)
assert "ndarray" in result.get("data", {})
assert np.array_equal(result["data"]["ndarray"], raw_response)
assert datadef == request["data"]
assert np.array_equal(features, request_data)
assert data_type == "data"

def test_create_grpc_reponse_text_ndarray():
user_model = UserObject()
request_data = np.array([["hello", "world"], ["hello", "another", "world"]])
datadef = scu.array_to_grpc_datadef("ndarray", request_data)
request = prediction_pb2.SeldonMessage(data=datadef)
(features, meta, datadef, data_type) = scu.extract_request_parts(request)
raw_response = np.array([["hello", "world"], ["here", "another"]])
sm = scu.construct_response(user_model, True, request, raw_response)
assert sm.data.WhichOneof("data_oneof") == "ndarray"
assert type(features[0]) == list
assert np.array_equal(sm.data.ndarray, raw_response)
assert datadef == request.data
assert np.array_equal(features, request_data)
assert data_type == "data"

def test_create_rest_reponse_ndarray():
user_model = UserObject()
request = {
Expand Down

0 comments on commit 60c9fd2

Please sign in to comment.