Skip to content

Commit 0afc8ee

Browse files
author
Fedor Baart
committed
scalar test
1 parent 7a110db commit 0afc8ee

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

mmi/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def send_array(socket, A, flags=0, copy=False, track=False, metadata=None):
2929
try:
3030
# If an array has a fill value assume it's an array with missings
3131
# store the fill_Value in the metadata and fill the array before sending.
32-
md['fill_value'] = A.fill_value
32+
# asscalar should work for scalar, 0d array or nd array of size 1
33+
md['fill_value'] = np.asscalar(A.fill_value)
3334
A = A.filled()
3435
except AttributeError:
3536
# no masked array, nothing to do

tests/test_simple.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_sndrcv(self):
1818
mmi.send_array(req, A)
1919
B, metadata = mmi.recv_array(rep)
2020
numpy.testing.assert_array_equal(A, B)
21+
2122
def test_metadata_only(self):
2223
"""send a message with only metadata"""
2324
req = ctx.socket(zmq.REQ)
@@ -42,3 +43,19 @@ def test_missing(self):
4243

4344

4445

46+
def test_missing_scalar(self):
47+
"""send an array with missing data"""
48+
A = np.array([1, 2, 3, 4])
49+
A = np.ma.masked_less(A, 2)
50+
# test if it works if we use a numpy scalar
51+
A.fill_value = np.int32(9999)
52+
req = ctx.socket(zmq.REQ)
53+
req.connect('tcp://localhost:9002')
54+
rep = ctx.socket(zmq.REP)
55+
rep.bind('tcp://*:9002')
56+
mmi.send_array(req, A)
57+
B, metadata = mmi.recv_array(rep)
58+
numpy.testing.assert_array_equal(A, B)
59+
60+
61+

0 commit comments

Comments
 (0)