Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 26, 2022
1 parent 2d8d856 commit 9f65aa2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tests/ludwig/utils/test_data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
figure_data_format_dataset,
get_abs_path,
hash_dict,
use_credentials,
NumpyEncoder,
use_credentials,
)

try:
Expand Down
26 changes: 13 additions & 13 deletions tests/ludwig/utils/test_server_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ def test_numpy_json_response():
response = NumpyJSONResponse()

# Test Python builtin data type encoding.
assert response.render(None) == "null".encode("utf-8")
assert response.render({}) == "{}".encode("utf-8")
assert response.render(1) == "1".encode("utf-8")
assert response.render(1.0) == "1.0".encode("utf-8")
assert response.render("a") == '"a"'.encode("utf-8")
assert response.render([0, 1, 2, 3, 4]) == "[0,1,2,3,4]".encode("utf-8")
assert response.render((0, 1, 2, 3, 4)) == "[0,1,2,3,4]".encode("utf-8")
assert response.render({0, 1, 2, 3, 4}) == "[0,1,2,3,4]".encode("utf-8")
assert response.render({"a": "b"}) == '{"a":"b"}'.encode("utf-8")
assert response.render(None) == b"null"
assert response.render({}) == b"{}"
assert response.render(1) == b"1"
assert response.render(1.0) == b"1.0"
assert response.render("a") == b'"a"'
assert response.render([0, 1, 2, 3, 4]) == b"[0,1,2,3,4]"
assert response.render((0, 1, 2, 3, 4)) == b"[0,1,2,3,4]"
assert response.render({0, 1, 2, 3, 4}) == b"[0,1,2,3,4]"
assert response.render({"a": "b"}) == b'{"a":"b"}'

# Test numpy data type encoding
for dtype in [np.byte, np.ubyte, np.short, np.ushort, np.int, np.uint, np.longlong, np.ulonglong]:
x = np.arange(5, dtype=dtype)
assert response.render(x) == "[0,1,2,3,4]".encode("utf-8")
assert response.render(x) == b"[0,1,2,3,4]"
for i in x:
assert response.render(i) == f"{i}".encode("utf-8")
assert response.render(i) == f"{i}".encode()

for dtype in [np.half, np.single, np.double, np.longdouble]:
x = np.arange(5, dtype=dtype)
assert response.render(x) == "[0.0,1.0,2.0,3.0,4.0]".encode("utf-8")
assert response.render(x) == b"[0.0,1.0,2.0,3.0,4.0]"
for i in x:
assert response.render(i) == f"{i}".encode("utf-8")
assert response.render(i) == f"{i}".encode()

0 comments on commit 9f65aa2

Please sign in to comment.