本文整理汇总了Python中km3pipe.dataclasses.Table.from_columns方法的典型用法代码示例。如果您正苦于以下问题:Python Table.from_columns方法的具体用法?Python Table.from_columns怎么用?Python Table.from_columns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类km3pipe.dataclasses.Table
的用法示例。
在下文中一共展示了Table.from_columns方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fromcolumns
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_columns [as 别名]
def test_fromcolumns(self):
n = 5
dlist = [
np.ones(n, dtype=int),
np.zeros(n, dtype=float),
0,
]
dt = np.dtype([('a', float), ('b', float), ('c', float)])
with pytest.raises(ValueError):
tab = Table(dlist, dtype=dt)
tab = Table.from_columns(dlist, dtype=dt)
print(tab.dtype)
print(tab.shape)
print(tab)
assert tab.h5loc == DEFAULT_H5LOC
assert isinstance(tab, Table)
tab = Table.from_columns(dlist, dtype=dt, h5loc='/foo')
print(tab.dtype)
print(tab.shape)
print(tab)
assert tab.h5loc == '/foo'
assert isinstance(tab, Table)
bad_dt = [('a', float), ('b', float), ('c', float), ('d', int)]
with pytest.raises(ValueError):
tab = Table.from_columns(dlist, dtype=bad_dt)
print(tab.dtype)
print(tab.shape)
print(tab)
示例2: test_add_tables_with_same_colnames_but_different_dtype_order
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_columns [as 别名]
def test_add_tables_with_same_colnames_but_different_dtype_order(self):
cols1 = ('b', 'a')
tab1 = Table.from_columns([[100, 200], [1, 2]], colnames=cols1)
self.assertTupleEqual(cols1, tab1.dtype.names)
cols2 = ('a', 'b')
tab2 = Table.from_columns([[3, 4, 5], [300, 400, 500]], colnames=cols2)
added_tab = tab1 + tab2
self.assertListEqual([1, 2, 3, 4, 5], list(added_tab.a))
self.assertListEqual([100, 200, 300, 400, 500], list(added_tab.b))
self.assertListEqual(
list(added_tab.dtype.names), list(tab1.dtype.names)
)
示例3: test_from_columns_with_colnames
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_columns [as 别名]
def test_from_columns_with_colnames(self):
t = Table.from_columns([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12],
[13, 14, 15], [16, 17, 18], [19, 20, 21]],
colnames=['a', 'b', 'c', 'd', 'e', 'f', 'g'])
print("t.a: {}".format(t.a))
assert np.allclose([1, 2, 3], t.a)
print("t.b: {}".format(t.b))
assert np.allclose([4, 5, 6], t.b)
示例4: test_from_columns_dim
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_columns [as 别名]
def test_from_columns_dim(self):
t = Table.from_columns([[1, 2, 3], [4, 5.0, 6]], colnames=['a', 'b'])
assert t.shape == (3, )
示例5: test_from_columns_with_mismatching_columns_and_dtypes_raises
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_columns [as 别名]
def test_from_columns_with_mismatching_columns_and_dtypes_raises(self):
with pytest.raises(ValueError):
Table.from_columns([[1, 2, 3], [4, 5, 6]],
dtype=np.dtype([('a', 'f4')]))
示例6: test_from_columns_with_colnames_upcasts
# 需要导入模块: from km3pipe.dataclasses import Table [as 别名]
# 或者: from km3pipe.dataclasses.Table import from_columns [as 别名]
def test_from_columns_with_colnames_upcasts(self):
t = Table.from_columns([[1, 2, 3], [4, 5.0, 6]], colnames=['a', 'b'])
assert t.dtype == np.dtype([('a', float), ('b', float)])