Skip to content

Commit

Permalink
Added round-trip Tests, changend bool_ to np.bool_
Browse files Browse the repository at this point in the history
Added test for scaler numpy bool, added numpy bool to mixed list test, removed modifications to pack test and changend bool_ to np.bool_
  • Loading branch information
PhyNerd committed Nov 23, 2017
1 parent 4874848 commit 3e19bce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pandas/io/msgpack/_packer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ from libc.limits cimport *

from pandas.io.msgpack.exceptions import PackValueError
from pandas.io.msgpack import ExtType
from numpy import bool_
import numpy as np


cdef extern from "../../src/msgpack/pack.h":
Expand Down Expand Up @@ -134,7 +134,7 @@ cdef class Packer(object):
while True:
if o is None:
ret = msgpack_pack_nil(&self.pk)
elif isinstance(o, (bool, bool_)):
elif isinstance(o, (bool, np.bool_)):
if o:
ret = msgpack_pack_true(&self.pk)
else:
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/io/msgpack/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pandas import compat
from pandas.compat import u, OrderedDict
from pandas.io.msgpack import packb, unpackb, Unpacker, Packer
from numpy import bool_


class TestPack(object):
Expand All @@ -26,7 +25,6 @@ def testPack(self):
(), ((),), ((), None,),
{None: 0},
(1 << 23),
bool_(1), bool_(0),
]
for td in test_data:
self.check(td)
Expand Down
11 changes: 10 additions & 1 deletion pandas/tests/io/test_packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ def test_scalar_float(self):
x_rec = self.encode_decode(x)
tm.assert_almost_equal(x, x_rec)

def test_scalar_bool(self):
x = np.bool_(1)
x_rec = self.encode_decode(x)
tm.assert_almost_equal(x, x_rec)

x = np.bool_(0)
x_rec = self.encode_decode(x)
tm.assert_almost_equal(x, x_rec)

def test_scalar_complex(self):
x = np.random.rand() + 1j * np.random.rand()
x_rec = self.encode_decode(x)
Expand Down Expand Up @@ -263,7 +272,7 @@ def test_numpy_array_complex(self):
x.dtype == x_rec.dtype)

def test_list_mixed(self):
x = [1.0, np.float32(3.5), np.complex128(4.25), u('foo')]
x = [1.0, np.float32(3.5), np.complex128(4.25), u('foo'), np.bool_(1)]
x_rec = self.encode_decode(x)
# current msgpack cannot distinguish list/tuple
tm.assert_almost_equal(tuple(x), x_rec)
Expand Down

0 comments on commit 3e19bce

Please sign in to comment.