Skip to content

Commit e0d3c06

Browse files
committed
Added round-trip Tests, changend bool_ to np.bool_
Added test for scaler numpy bool, added numpy bool to mixed list test, removed modifications to pack test and changend bool_ to np.bool_
1 parent 0cac8d3 commit e0d3c06

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

pandas/io/msgpack/_packer.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from libc.limits cimport *
88

99
from pandas.io.msgpack.exceptions import PackValueError
1010
from pandas.io.msgpack import ExtType
11-
from numpy import bool_
11+
import numpy as np
1212

1313

1414
cdef extern from "../../src/msgpack/pack.h":
@@ -134,7 +134,7 @@ cdef class Packer(object):
134134
while True:
135135
if o is None:
136136
ret = msgpack_pack_nil(&self.pk)
137-
elif isinstance(o, (bool, bool_)):
137+
elif isinstance(o, (bool, np.bool_)):
138138
if o:
139139
ret = msgpack_pack_true(&self.pk)
140140
else:

pandas/tests/io/msgpack/test_pack.py

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from pandas import compat
88
from pandas.compat import u, OrderedDict
99
from pandas.io.msgpack import packb, unpackb, Unpacker, Packer
10-
from numpy import bool_
1110

1211

1312
class TestPack(object):
@@ -26,7 +25,6 @@ def testPack(self):
2625
(), ((),), ((), None,),
2726
{None: 0},
2827
(1 << 23),
29-
bool_(1), bool_(0),
3028
]
3129
for td in test_data:
3230
self.check(td)

pandas/tests/io/test_packers.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ def test_scalar_float(self):
180180
x_rec = self.encode_decode(x)
181181
tm.assert_almost_equal(x, x_rec)
182182

183+
def test_scalar_bool(self):
184+
x = np.bool_(1)
185+
x_rec = self.encode_decode(x)
186+
tm.assert_almost_equal(x, x_rec)
187+
188+
x = np.bool_(0)
189+
x_rec = self.encode_decode(x)
190+
tm.assert_almost_equal(x, x_rec)
191+
183192
def test_scalar_complex(self):
184193
x = np.random.rand() + 1j * np.random.rand()
185194
x_rec = self.encode_decode(x)
@@ -263,7 +272,7 @@ def test_numpy_array_complex(self):
263272
x.dtype == x_rec.dtype)
264273

265274
def test_list_mixed(self):
266-
x = [1.0, np.float32(3.5), np.complex128(4.25), u('foo')]
275+
x = [1.0, np.float32(3.5), np.complex128(4.25), u('foo'), np.bool_(1)]
267276
x_rec = self.encode_decode(x)
268277
# current msgpack cannot distinguish list/tuple
269278
tm.assert_almost_equal(tuple(x), x_rec)

0 commit comments

Comments
 (0)