本文整理汇总了Python中holoviews.Dataset.range方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.range方法的具体用法?Python Dataset.range怎么用?Python Dataset.range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类holoviews.Dataset
的用法示例。
在下文中一共展示了Dataset.range方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HomogeneousColumnTests
# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import range [as 别名]
class HomogeneousColumnTests(object):
"""
Tests for data formats that require all dataset to have the same
type (e.g numpy arrays)
"""
def init_column_data(self):
self.xs = np.array(range(11))
self.xs_2 = self.xs**2
self.y_ints = self.xs*2
self.dataset_hm = Dataset((self.xs, self.y_ints),
kdims=['x'], vdims=['y'])
self.dataset_hm_alias = Dataset((self.xs, self.y_ints),
kdims=[('x', 'X')], vdims=[('y', 'Y')])
# Test the array constructor (homogeneous data) to be supported by
# all interfaces.
def test_dataset_array_init_hm(self):
dataset = Dataset(np.column_stack([self.xs, self.xs_2]),
kdims=['x'], vdims=['x2'])
self.assertTrue(isinstance(dataset.data, self.data_type))
def test_dataset_array_init_hm_tuple_dims(self):
dataset = Dataset(np.column_stack([self.xs, self.xs_2]),
kdims=[('x', 'X')], vdims=[('x2', 'X2')])
self.assertTrue(isinstance(dataset.data, self.data_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_type))
def test_dataset_dataframe_init_hm_alias(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', 'X-label')], vdims=[('x2', 'X2-label')])
self.assertTrue(isinstance(dataset.data, self.data_type))
def test_dataset_empty_list_init(self):
dataset = Dataset([], kdims=['x'], vdims=['y'])
for d in 'xy':
self.assertEqual(dataset.dimension_values(d), np.array([]))
def test_dataset_dict_dim_not_found_raises_on_array(self):
with self.assertRaises(ValueError):
Dataset({'x': np.zeros(5)}, kdims=['Test'], vdims=[])
def test_dataset_dict_dim_not_found_raises_on_scalar(self):
with self.assertRaises(ValueError):
Dataset({'x': 1}, kdims=['Test'], vdims=[])
# 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_hm(self):
ds = Dataset(([2, 2, 1], [2,1,2], [0.1, 0.2, 0.3]),
kdims=['x', 'y'], vdims=['z']).sort()
ds_sorted = Dataset(([1, 2, 2], [2, 1, 2], [0.3, 0.2, 0.1]),
kdims=['x', 'y'], vdims=['z'])
self.assertEqual(ds.sort(), ds_sorted)
def test_dataset_sort_reverse_hm(self):
ds = Dataset(([2, 1, 2, 1], [2, 2, 1, 1], [0.1, 0.2, 0.3, 0.4]),
kdims=['x', 'y'], vdims=['z'])
ds_sorted = Dataset(([2, 2, 1, 1], [2, 1, 2, 1], [0.1, 0.3, 0.2, 0.4]),
kdims=['x', 'y'], vdims=['z'])
self.assertEqual(ds.sort(reverse=True), ds_sorted)
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_sort_reverse_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, -xs_2]),
kdims=['x'], vdims=['y'])
#.........这里部分代码省略.........
示例2: test_dataset_range_with_dimension_range
# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import range [as 别名]
def test_dataset_range_with_dimension_range(self):
dt64 = np.array([np.datetime64(datetime.datetime(2017, 1, i)) for i in range(1, 4)])
ds = Dataset(dt64, [Dimension('Date', range=(dt64[0], dt64[-1]))])
self.assertEqual(ds.range('Date'), (dt64[0], dt64[-1]))
示例3: test_dataset_mixed_type_range
# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import range [as 别名]
def test_dataset_mixed_type_range(self):
ds = Dataset((['A', 'B', 'C', None],), 'A')
self.assertEqual(ds.range(0), ('A', 'C'))
示例4: HomogeneousColumnTypes
# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import range [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]},
#.........这里部分代码省略.........