本文整理汇总了Python中blaze.data.CSV.chunks方法的典型用法代码示例。如果您正苦于以下问题:Python CSV.chunks方法的具体用法?Python CSV.chunks怎么用?Python CSV.chunks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blaze.data.CSV
的用法示例。
在下文中一共展示了CSV.chunks方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_chunks
# 需要导入模块: from blaze.data import CSV [as 别名]
# 或者: from blaze.data.CSV import chunks [as 别名]
def test_chunks(self):
dd = CSV(self.csv_file, schema=self.schema)
vals = []
for el in dd.chunks(blen=2):
self.assertTrue(isinstance(el, nd.array))
vals.extend(nd.as_py(el))
self.assertEqual(vals, [
{u'f0': u'k1', u'f1': u'v1', u'f2': 1, u'f3': False},
{u'f0': u'k2', u'f1': u'v2', u'f2': 2, u'f3': True},
{u'f0': u'k3', u'f1': u'v3', u'f2': 3, u'f3': False}])
示例2: test_append
# 需要导入模块: from blaze.data import CSV [as 别名]
# 或者: from blaze.data.CSV import chunks [as 别名]
def test_append(self):
# Get a private file so as to not mess the original one
csv_file = tempfile.mktemp(".csv")
with open(csv_file, "w") as f:
f.write(self.buf)
dd = CSV(csv_file, schema=self.schema, mode='r+')
dd.extend([["k4", "v4", 4, True]])
vals = [nd.as_py(v) for v in dd.chunks(blen=2)]
self.assertEqual(vals, [
[{u'f0': u'k1', u'f1': u'v1', u'f2': 1, u'f3': False},
{u'f0': u'k2', u'f1': u'v2', u'f2': 2, u'f3': True}],
[{u'f0': u'k3', u'f1': u'v3', u'f2': 3, u'f3': False},
{u'f0': u'k4', u'f1': u'v4', u'f2': 4, u'f3': True}]])
self.assertRaises(ValueError, lambda: dd.extend([3.3]))
os.remove(csv_file)
示例3: test_chunks
# 需要导入模块: from blaze.data import CSV [as 别名]
# 或者: from blaze.data.CSV import chunks [as 别名]
def test_chunks(self):
with filetext('1,1\n2,2\n3,3\n4,4\n') as fn:
dd = CSV(fn, schema='2 * int32')
assert all(isinstance(chunk, nd.array) for chunk in dd.chunks())
self.assertEquals(len(list(dd.chunks(blen=2))), 2)
self.assertEquals(len(list(dd.chunks(blen=3))), 2)
示例4: test_chunks
# 需要导入模块: from blaze.data import CSV [as 别名]
# 或者: from blaze.data.CSV import chunks [as 别名]
def test_chunks():
with filetext('1,1\n2,2\n3,3\n4,4\n') as fn:
dd = CSV(fn, schema='{a: int32, b: int32}')
assert all(isinstance(chunk, nd.array) for chunk in dd.chunks())
assert len(list(dd.chunks(blen=2))) == 2
assert len(list(dd.chunks(blen=3))) == 2