本文整理汇总了Python中holoviews.Dataset.add_dimension方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.add_dimension方法的具体用法?Python Dataset.add_dimension怎么用?Python Dataset.add_dimension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类holoviews.Dataset
的用法示例。
在下文中一共展示了Dataset.add_dimension方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HomogeneousColumnTests
# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import add_dimension [as 别名]
#.........这里部分代码省略.........
self.assertEqual(redimmed.kdims[0].soft_range, (-100,30))
def test_dataset_redim_hm_kdim_alias(self):
redimmed = self.dataset_hm_alias.redim(x='Time')
self.assertEqual(redimmed.dimension_values('Time'),
self.dataset_hm_alias.dimension_values('x'))
def test_dataset_redim_hm_vdim(self):
redimmed = self.dataset_hm.redim(y='Value')
self.assertEqual(redimmed.dimension_values('Value'),
self.dataset_hm.dimension_values('y'))
def test_dataset_redim_hm_vdim_alias(self):
redimmed = self.dataset_hm_alias.redim(y=Dimension(('val', 'Value')))
self.assertEqual(redimmed.dimension_values('Value'),
self.dataset_hm_alias.dimension_values('y'))
def test_dataset_sample_hm(self):
samples = self.dataset_hm.sample([0, 5, 10]).dimension_values('y')
self.assertEqual(samples, np.array([0, 10, 20]))
def test_dataset_sample_hm_alias(self):
samples = self.dataset_hm_alias.sample([0, 5, 10]).dimension_values('y')
self.assertEqual(samples, np.array([0, 10, 20]))
def test_dataset_array_hm(self):
self.assertEqual(self.dataset_hm.array(),
np.column_stack([self.xs, self.y_ints]))
def test_dataset_array_hm_alias(self):
self.assertEqual(self.dataset_hm_alias.array(),
np.column_stack([self.xs, self.y_ints]))
def test_dataset_add_dimensions_value_hm(self):
table = self.dataset_hm.add_dimension('z', 1, 0)
self.assertEqual(table.kdims[1], 'z')
self.compare_arrays(table.dimension_values('z'), np.zeros(table.shape[0]))
def test_dataset_add_dimensions_values_hm(self):
table = self.dataset_hm.add_dimension('z', 1, range(1,12))
self.assertEqual(table.kdims[1], 'z')
self.compare_arrays(table.dimension_values('z'), np.array(list(range(1,12))))
def test_dataset_slice_hm(self):
dataset_slice = Dataset({'x':range(5, 9), 'y':[2 * i for i in range(5, 9)]},
kdims=['x'], vdims=['y'])
self.assertEqual(self.dataset_hm[5:9], dataset_slice)
def test_dataset_slice_hm_alias(self):
dataset_slice = Dataset({'x':range(5, 9), 'y':[2 * i for i in range(5, 9)]},
kdims=[('x', 'X')], vdims=[('y', 'Y')])
self.assertEqual(self.dataset_hm_alias[5:9], dataset_slice)
def test_dataset_slice_fn_hm(self):
dataset_slice = Dataset({'x':range(5, 9), 'y':[2 * i for i in range(5, 9)]},
kdims=['x'], vdims=['y'])
self.assertEqual(self.dataset_hm[lambda x: (x >= 5) & (x < 9)], dataset_slice)
def test_dataset_1D_reduce_hm(self):
dataset = Dataset({'x':self.xs, 'y':self.y_ints}, kdims=['x'], vdims=['y'])
self.assertEqual(dataset.reduce('x', np.mean), 10)
def test_dataset_1D_reduce_hm_alias(self):
dataset = Dataset({'x':self.xs, 'y':self.y_ints}, kdims=[('x', 'X')],
vdims=[('y', 'Y')])
self.assertEqual(dataset.reduce('X', np.mean), 10)
示例2: HeterogeneousColumnTests
# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import add_dimension [as 别名]
#.........这里部分代码省略.........
group1 = {'age':[10,16], 'weight':[15,18], 'height':[0.8,0.6]}
group2 = {'age':[12], 'weight':[10], 'height':[0.8]}
grouped = HoloMap([('M', Dataset(group1, kdims=[('age', 'Age')],
vdims=self.alias_vdims)),
('F', Dataset(group2, kdims=[('age', 'Age')],
vdims=self.alias_vdims))],
kdims=[('gender', 'Gender')], sort=False)
self.assertEqual(self.alias_table.groupby('Gender'), grouped)
def test_dataset_groupby_second_dim(self):
group1 = {'Gender':['M'], 'Weight':[15], 'Height':[0.8]}
group2 = {'Gender':['M'], 'Weight':[18], 'Height':[0.6]}
group3 = {'Gender':['F'], 'Weight':[10], 'Height':[0.8]}
grouped = HoloMap([(10, Dataset(group1, kdims=['Gender'], vdims=self.vdims)),
(16, Dataset(group2, kdims=['Gender'], vdims=self.vdims)),
(12, Dataset(group3, kdims=['Gender'], vdims=self.vdims))],
kdims=['Age'], sort=False)
self.assertEqual(self.table.groupby(['Age']), grouped)
def test_dataset_groupby_dynamic(self):
grouped_dataset = self.table.groupby('Gender', dynamic=True)
self.assertEqual(grouped_dataset['M'],
self.table.select(Gender='M').reindex(['Age']))
self.assertEqual(grouped_dataset['F'],
self.table.select(Gender='F').reindex(['Age']))
def test_dataset_groupby_dynamic_alias(self):
grouped_dataset = self.alias_table.groupby('Gender', dynamic=True)
self.assertEqual(grouped_dataset['M'],
self.alias_table.select(gender='M').reindex(['Age']))
self.assertEqual(grouped_dataset['F'],
self.alias_table.select(gender='F').reindex(['Age']))
def test_dataset_add_dimensions_value_ht(self):
table = self.dataset_ht.add_dimension('z', 1, 0)
self.assertEqual(table.kdims[1], 'z')
self.compare_arrays(table.dimension_values('z'), np.zeros(table.shape[0]))
def test_dataset_add_dimensions_value_ht_alias(self):
table = self.dataset_ht.add_dimension(('z', 'Z'), 1, 0)
self.assertEqual(table.kdims[1], 'z')
self.compare_arrays(table.dimension_values('z'), np.zeros(table.shape[0]))
def test_dataset_add_dimensions_values_ht(self):
table = self.dataset_ht.add_dimension('z', 1, range(1,12))
self.assertEqual(table.kdims[1], 'z')
self.compare_arrays(table.dimension_values('z'), np.array(list(range(1,12))))
def test_redim_with_extra_dimension(self):
dataset = self.dataset_ht.add_dimension('Temp', 0, 0).clone(kdims=['x', 'y'], vdims=[])
redimmed = dataset.redim(x='Time')
self.assertEqual(redimmed.dimension_values('Time'),
self.dataset_ht.dimension_values('x'))
# Indexing
def test_dataset_index_row_gender_female(self):
indexed = Dataset({'Gender':['F'], 'Age':[12],
'Weight':[10], 'Height':[0.8]},
kdims=self.kdims, vdims=self.vdims)
row = self.table['F',:]
self.assertEquals(row, indexed)
def test_dataset_index_rows_gender_male(self):
row = self.table['M',:]
indexed = Dataset({'Gender':['M', 'M'], 'Age':[10, 16],
示例3: HomogeneousColumnTypes
# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import add_dimension [as 别名]
class HomogeneousColumnTypes(object):
"""
Tests for data formats that require all dataset to have the same
type (e.g numpy arrays)
"""
def setUp(self):
self.restore_datatype = Dataset.datatype
self.data_instance_type = None
def init_data(self):
self.xs = range(11)
self.xs_2 = [el**2 for el in self.xs]
self.y_ints = [i*2 for i in range(11)]
self.dataset_hm = Dataset((self.xs, self.y_ints),
kdims=['x'], vdims=['y'])
def tearDown(self):
Dataset.datatype = self.restore_datatype
# Test the array constructor (homogenous data) to be supported by
# all interfaces.
def test_dataset_array_init_hm(self):
"Tests support for arrays (homogeneous)"
dataset = Dataset(np.column_stack([self.xs, self.xs_2]),
kdims=['x'], vdims=['x2'])
self.assertTrue(isinstance(dataset.data, self.data_instance_type))
def test_dataset_ndelement_init_hm(self):
"Tests support for homogeneous NdElement (backwards compatibility)"
dataset = Dataset(NdElement(zip(self.xs, self.xs_2),
kdims=['x'], vdims=['x2']))
self.assertTrue(isinstance(dataset.data, self.data_instance_type))
def test_dataset_dataframe_init_hm(self):
"Tests support for homogeneous DataFrames"
if pd is None:
raise SkipTest("Pandas not available")
dataset = Dataset(pd.DataFrame({'x':self.xs, 'x2':self.xs_2}),
kdims=['x'], vdims=[ 'x2'])
self.assertTrue(isinstance(dataset.data, self.data_instance_type))
# Properties and information
def test_dataset_shape(self):
self.assertEqual(self.dataset_hm.shape, (11, 2))
def test_dataset_range(self):
self.assertEqual(self.dataset_hm.range('y'), (0, 20))
def test_dataset_closest(self):
closest = self.dataset_hm.closest([0.51, 1, 9.9])
self.assertEqual(closest, [1., 1., 10.])
# Operations
def test_dataset_sort_vdim_hm(self):
xs_2 = np.array(self.xs_2)
dataset = Dataset(np.column_stack([self.xs, -xs_2]),
kdims=['x'], vdims=['y'])
dataset_sorted = Dataset(np.column_stack([self.xs[::-1], -xs_2[::-1]]),
kdims=['x'], vdims=['y'])
self.assertEqual(dataset.sort('y'), dataset_sorted)
def test_dataset_sample_hm(self):
samples = self.dataset_hm.sample([0, 5, 10]).dimension_values('y')
self.assertEqual(samples, np.array([0, 10, 20]))
def test_dataset_array_hm(self):
self.assertEqual(self.dataset_hm.array(),
np.column_stack([self.xs, self.y_ints]))
def test_dataset_add_dimensions_value_hm(self):
table = self.dataset_hm.add_dimension('z', 1, 0)
self.assertEqual(table.kdims[1], 'z')
self.compare_arrays(table.dimension_values('z'), np.zeros(len(table)))
def test_dataset_add_dimensions_values_hm(self):
table = self.dataset_hm.add_dimension('z', 1, range(1,12))
self.assertEqual(table.kdims[1], 'z')
self.compare_arrays(table.dimension_values('z'), np.array(list(range(1,12))))
def test_dataset_slice_hm(self):
dataset_slice = Dataset({'x':range(5, 9), 'y':[2 * i for i in range(5, 9)]},
kdims=['x'], vdims=['y'])
self.assertEqual(self.dataset_hm[5:9], dataset_slice)
def test_dataset_slice_fn_hm(self):
dataset_slice = Dataset({'x':range(5, 9), 'y':[2 * i for i in range(5, 9)]},
kdims=['x'], vdims=['y'])
self.assertEqual(self.dataset_hm[lambda x: (x >= 5) & (x < 9)], dataset_slice)
def test_dataset_1D_reduce_hm(self):
dataset = Dataset({'x':self.xs, 'y':self.y_ints}, kdims=['x'], vdims=['y'])
self.assertEqual(dataset.reduce('x', np.mean), 10)
def test_dataset_2D_reduce_hm(self):
dataset = Dataset({'x':self.xs, 'y':self.y_ints, 'z':[el ** 2 for el in self.y_ints]},
#.........这里部分代码省略.........
示例4: GridDatasetTest
# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import add_dimension [as 别名]
class GridDatasetTest(HomogeneousColumnTypes, ComparisonTestCase):
"""
Test of the NdDataset interface (mostly for backwards compatibility)
"""
def setUp(self):
self.restore_datatype = Dataset.datatype
Dataset.datatype = ['grid']
self.data_instance_type = dict
self.init_data()
def init_data(self):
self.xs = range(11)
self.xs_2 = [el**2 for el in self.xs]
self.y_ints = [i*2 for i in range(11)]
self.dataset_hm = Dataset((self.xs, self.y_ints),
kdims=['x'], vdims=['y'])
def test_dataset_array_init_hm(self):
"Tests support for arrays (homogeneous)"
exception = "None of the available storage backends "\
"were able to support the supplied data format."
with self.assertRaisesRegexp(Exception, exception):
Dataset(np.column_stack([self.xs, self.xs_2]),
kdims=['x'], vdims=['x2'])
def test_dataset_dataframe_init_hm(self):
"Tests support for homogeneous DataFrames"
if pd is None:
raise SkipTest("Pandas not available")
exception = "None of the available storage backends "\
"were able to support the supplied data format."
with self.assertRaisesRegexp(Exception, exception):
Dataset(pd.DataFrame({'x':self.xs, 'x2':self.xs_2}),
kdims=['x'], vdims=['x2'])
def test_dataset_ndelement_init_hm(self):
"Tests support for homogeneous NdElement (backwards compatibility)"
exception = "None of the available storage backends "\
"were able to support the supplied data format."
with self.assertRaisesRegexp(Exception, exception):
Dataset(NdElement(zip(self.xs, self.xs_2),
kdims=['x'], vdims=['x2']))
def test_dataset_2D_aggregate_partial_hm(self):
array = np.random.rand(11, 11)
dataset = Dataset({'x':self.xs, 'y':self.y_ints, 'z': array},
kdims=['x', 'y'], vdims=['z'])
self.assertEqual(dataset.aggregate(['x'], np.mean),
Dataset({'x':self.xs, 'z': np.mean(array, axis=0)},
kdims=['x'], vdims=['z']))
def test_dataset_2D_reduce_hm(self):
array = np.random.rand(11, 11)
dataset = Dataset({'x':self.xs, 'y':self.y_ints, 'z': array},
kdims=['x', 'y'], vdims=['z'])
self.assertEqual(np.array(dataset.reduce(['x', 'y'], np.mean)),
np.mean(array))
def test_dataset_add_dimensions_value_hm(self):
with self.assertRaisesRegexp(Exception, 'Cannot add key dimension to a dense representation.'):
self.dataset_hm.add_dimension('z', 1, 0)
def test_dataset_add_dimensions_values_hm(self):
table = self.dataset_hm.add_dimension('z', 1, range(1,12), vdim=True)
self.assertEqual(table.vdims[1], 'z')
self.compare_arrays(table.dimension_values('z'), np.array(list(range(1,12))))
def test_dataset_sort_vdim_hm(self):
exception = ('Compressed format cannot be sorted, either instantiate '
'in the desired order or use the expanded format.')
with self.assertRaisesRegexp(Exception, exception):
self.dataset_hm.sort('y')
def test_dataset_groupby(self):
self.assertEqual(self.dataset_hm.groupby('x').keys(), list(self.xs))
示例5: HeterogeneousColumnTypes
# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import add_dimension [as 别名]
#.........这里部分代码省略.........
reduced = Dataset({'Weight':[14.333333333333334], 'Height':[0.73333333333333339]},
kdims=[], vdims=self.vdims)
self.assertEqual(self.table.reduce(function=np.mean), reduced)
def test_dataset_2D_partial_reduce_ht(self):
dataset = Dataset({'x':self.xs, 'y':self.ys, 'z':self.zs},
kdims=['x', 'y'], vdims=['z'])
reduced = Dataset({'x':self.xs, 'z':self.zs},
kdims=['x'], vdims=['z'])
self.assertEqual(dataset.reduce(['y'], np.mean), reduced)
def test_column_aggregate_ht(self):
aggregated = Dataset({'Gender':['M', 'F'], 'Weight':[16.5, 10], 'Height':[0.7, 0.8]},
kdims=self.kdims[:1], vdims=self.vdims)
self.compare_dataset(self.table.aggregate(['Gender'], np.mean), aggregated)
def test_dataset_2D_aggregate_partial_ht(self):
dataset = Dataset({'x':self.xs, 'y':self.ys, 'z':self.zs},
kdims=['x', 'y'], vdims=['z'])
reduced = Dataset({'x':self.xs, 'z':self.zs},
kdims=['x'], vdims=['z'])
self.assertEqual(dataset.aggregate(['x'], np.mean), reduced)
def test_dataset_groupby(self):
group1 = {'Age':[10,16], 'Weight':[15,18], 'Height':[0.8,0.6]}
group2 = {'Age':[12], 'Weight':[10], 'Height':[0.8]}
grouped = HoloMap([('M', Dataset(group1, kdims=['Age'], vdims=self.vdims)),
('F', Dataset(group2, kdims=['Age'], vdims=self.vdims))],
kdims=['Gender'])
self.assertEqual(self.table.groupby(['Gender']), grouped)
def test_dataset_add_dimensions_value_ht(self):
table = self.dataset_ht.add_dimension('z', 1, 0)
self.assertEqual(table.kdims[1], 'z')
self.compare_arrays(table.dimension_values('z'), np.zeros(len(table)))
def test_dataset_add_dimensions_values_ht(self):
table = self.dataset_ht.add_dimension('z', 1, range(1,12))
self.assertEqual(table.kdims[1], 'z')
self.compare_arrays(table.dimension_values('z'), np.array(list(range(1,12))))
# Indexing
def test_dataset_index_row_gender_female(self):
indexed = Dataset({'Gender':['F'], 'Age':[12],
'Weight':[10], 'Height':[0.8]},
kdims=self.kdims, vdims=self.vdims)
row = self.table['F',:]
self.assertEquals(row, indexed)
def test_dataset_index_rows_gender_male(self):
row = self.table['M',:]
indexed = Dataset({'Gender':['M', 'M'], 'Age':[10, 16],
'Weight':[15,18], 'Height':[0.8,0.6]},
kdims=self.kdims, vdims=self.vdims)
self.assertEquals(row, indexed)
def test_dataset_index_row_age(self):
indexed = Dataset({'Gender':['F'], 'Age':[12],
'Weight':[10], 'Height':[0.8]},
kdims=self.kdims, vdims=self.vdims)
self.assertEquals(self.table[:, 12], indexed)
def test_dataset_index_item_table(self):