本文整理汇总了Python中pandas.msgpack.Unpacker.feed方法的典型用法代码示例。如果您正苦于以下问题:Python Unpacker.feed方法的具体用法?Python Unpacker.feed怎么用?Python Unpacker.feed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.msgpack.Unpacker
的用法示例。
在下文中一共展示了Unpacker.feed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_incorrect_type_array
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_incorrect_type_array():
unpacker = Unpacker()
unpacker.feed(packb(1))
try:
unpacker.read_array_header()
assert 0, 'should raise exception'
except UnexpectedTypeException:
assert 1, 'okay'
示例2: test_correct_type_nested_array
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_correct_type_nested_array():
unpacker = Unpacker()
unpacker.feed(packb({'a': ['b', 'c', 'd']}))
try:
unpacker.read_array_header()
assert 0, 'should raise exception'
except UnexpectedTypeException:
assert 1, 'okay'
示例3: test_incorrect_type_nested_map
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_incorrect_type_nested_map():
unpacker = Unpacker()
unpacker.feed(packb([{'a': 'b'}]))
try:
unpacker.read_map_header()
assert 0, 'should raise exception'
except UnexpectedTypeException:
assert 1, 'okay'
示例4: test_foobar_skip
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_foobar_skip(self):
unpacker = Unpacker(read_size=3, use_list=1)
unpacker.feed(b"foobar")
assert unpacker.unpack() == ord(b"f")
unpacker.skip()
assert unpacker.unpack() == ord(b"o")
unpacker.skip()
assert unpacker.unpack() == ord(b"a")
unpacker.skip()
self.assertRaises(OutOfData, unpacker.unpack)
示例5: test_max_map_len
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_max_map_len(self):
d = {1: 2, 3: 4, 5: 6}
packed = packb(d)
unpacker = Unpacker(max_map_len=3)
unpacker.feed(packed)
assert unpacker.unpack() == d
unpacker = Unpacker(max_map_len=2)
unpacker.feed(packed)
self.assertRaises(ValueError, unpacker.unpack)
示例6: test_max_bin_len
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_max_bin_len(self):
d = b'x' * 3
packed = packb(d, use_bin_type=True)
unpacker = Unpacker(max_bin_len=3)
unpacker.feed(packed)
assert unpacker.unpack() == d
unpacker = Unpacker(max_bin_len=2)
unpacker.feed(packed)
self.assertRaises(ValueError, unpacker.unpack)
示例7: test_max_ext_len
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_max_ext_len(self):
d = ExtType(42, b"abc")
packed = packb(d)
unpacker = Unpacker(max_ext_len=3)
unpacker.feed(packed)
assert unpacker.unpack() == d
unpacker = Unpacker(max_ext_len=2)
unpacker.feed(packed)
self.assertRaises(ValueError, unpacker.unpack)
示例8: test_read_map_header
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_read_map_header():
unpacker = Unpacker()
unpacker.feed(packb({'a': 'A'}))
assert unpacker.read_map_header() == 1
assert unpacker.unpack() == B'a'
assert unpacker.unpack() == B'A'
try:
unpacker.unpack()
assert 0, 'should raise exception'
except OutOfData:
assert 1, 'okay'
示例9: test_max_str_len
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_max_str_len(self):
d = 'x' * 3
packed = packb(d)
unpacker = Unpacker(max_str_len=3, encoding='utf-8')
unpacker.feed(packed)
assert unpacker.unpack() == d
unpacker = Unpacker(max_str_len=2, encoding='utf-8')
unpacker.feed(packed)
self.assertRaises(ValueError, unpacker.unpack)
示例10: test_max_array_len
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_max_array_len(self):
d = [1, 2, 3]
packed = packb(d)
unpacker = Unpacker(max_array_len=3)
unpacker.feed(packed)
assert unpacker.unpack() == d
unpacker = Unpacker(max_array_len=2)
unpacker.feed(packed)
self.assertRaises(ValueError, unpacker.unpack)
示例11: test_read_array_header
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_read_array_header():
unpacker = Unpacker()
unpacker.feed(packb(['a', 'b', 'c']))
assert unpacker.read_array_header() == 3
assert unpacker.unpack() == b'a'
assert unpacker.unpack() == b'b'
assert unpacker.unpack() == b'c'
try:
unpacker.unpack()
assert 0, 'should raise exception'
except OutOfData:
assert 1, 'okay'
示例12: test_write_bytes
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_write_bytes():
unpacker = Unpacker()
unpacker.feed(b'abc')
f = io.BytesIO()
assert unpacker.unpack(f.write) == ord('a')
assert f.getvalue() == b'a'
f = io.BytesIO()
assert unpacker.skip(f.write) is None
assert f.getvalue() == b'b'
f = io.BytesIO()
assert unpacker.skip() is None
assert f.getvalue() == b''
示例13: test_readbytes
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_readbytes(self):
unpacker = Unpacker(read_size=3)
unpacker.feed(b'foobar')
assert unpacker.unpack() == ord(b'f')
assert unpacker.read_bytes(3) == b'oob'
assert unpacker.unpack() == ord(b'a')
assert unpacker.unpack() == ord(b'r')
# Test buffer refill
unpacker = Unpacker(compat.BytesIO(b'foobar'), read_size=3)
assert unpacker.unpack() == ord(b'f')
assert unpacker.read_bytes(3) == b'oob'
assert unpacker.unpack() == ord(b'a')
assert unpacker.unpack() == ord(b'r')
示例14: test_foobar
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_foobar(self):
unpacker = Unpacker(read_size=3, use_list=1)
unpacker.feed(b"foobar")
assert unpacker.unpack() == ord(b"f")
assert unpacker.unpack() == ord(b"o")
assert unpacker.unpack() == ord(b"o")
assert unpacker.unpack() == ord(b"b")
assert unpacker.unpack() == ord(b"a")
assert unpacker.unpack() == ord(b"r")
self.assertRaises(OutOfData, unpacker.unpack)
unpacker.feed(b"foo")
unpacker.feed(b"bar")
k = 0
for o, e in zip(unpacker, "foobarbaz"):
assert o == ord(e)
k += 1
assert k == len(b"foobar")
示例15: test_unpacker_hook_refcnt
# 需要导入模块: from pandas.msgpack import Unpacker [as 别名]
# 或者: from pandas.msgpack.Unpacker import feed [as 别名]
def test_unpacker_hook_refcnt(self):
if not hasattr(sys, 'getrefcount'):
raise nose.SkipTest('no sys.getrefcount()')
result = []
def hook(x):
result.append(x)
return x
basecnt = sys.getrefcount(hook)
up = Unpacker(object_hook=hook, list_hook=hook)
assert sys.getrefcount(hook) >= basecnt + 2
up.feed(packb([{}]))
up.feed(packb([{}]))
assert up.unpack() == [{}]
assert up.unpack() == [{}]
assert result == [{}, [{}], {}, [{}]]
del up
assert sys.getrefcount(hook) == basecnt