Skip to content

Commit

Permalink
fix: empty lists were not serialized property, but send as empty ndarray
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Feb 8, 2018
1 parent 6e1f088 commit 1ee095d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ipyvolume/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,11 @@ def array_sequence_to_binary_or_json(ar, obj=None):
pass
if isinstance(element, string_types):
return array_to_json(ar)
if dimension == 0: # scalars are passed as is (json)
return element
if dimension == 0: # scalars are passed as is (json), empty lists as well
if isinstance(element, np.ndarray): # must be an empty list
return []
else:
return element
if isinstance(ar, (list, tuple, np.ndarray)): # ok, at least 1d
if isinstance(ar[0], (list, tuple, np.ndarray)): # ok, 2d
return [array_to_binary(ar[k]) for k in range(len(ar))]
Expand Down
14 changes: 14 additions & 0 deletions ipyvolume/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ipyvolume.examples
import ipyvolume.datasets
import ipyvolume.utils
import ipyvolume.serialize
import numpy as np
import os
import shutil
Expand All @@ -16,6 +17,19 @@
shutil.rmtree("tmp")
os.makedirs("tmp")

def test_serialize():
assert ipyvolume.serialize.array_sequence_to_binary_or_json(1) == 1
assert ipyvolume.serialize.array_sequence_to_binary_or_json([]) == []
empty_array = np.array([])
assert ipyvolume.serialize.array_sequence_to_binary_or_json(empty_array) == []
assert type(ipyvolume.serialize.array_sequence_to_binary_or_json(empty_array)) == list

value = np.asarray(5)
assert ipyvolume.serialize.array_sequence_to_binary_or_json(value) == 5

value = np.asarray(5)
assert ipyvolume.serialize.array_sequence_to_binary_or_json(value) == 5

def test_figure():
f1 = p3.figure()
f2 = p3.figure(2)
Expand Down

0 comments on commit 1ee095d

Please sign in to comment.