当前位置: 首页>>代码示例>>Python>>正文


Python Columns.sort方法代码示例

本文整理汇总了Python中holoviews.Columns.sort方法的典型用法代码示例。如果您正苦于以下问题:Python Columns.sort方法的具体用法?Python Columns.sort怎么用?Python Columns.sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在holoviews.Columns的用法示例。


在下文中一共展示了Columns.sort方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_columns_sort_vdim_hm

# 需要导入模块: from holoviews import Columns [as 别名]
# 或者: from holoviews.Columns import sort [as 别名]
 def test_columns_sort_vdim_hm(self):
     xs_2 = np.array(self.xs_2)
     columns = Columns(np.column_stack([self.xs, -xs_2]),
                              kdims=['x'], vdims=['y'])
     columns_sorted = Columns(np.column_stack([self.xs[::-1], -xs_2[::-1]]),
                              kdims=['x'], vdims=['y'])
     self.assertEqual(columns.sort('y'), columns_sorted)
开发者ID:pittmiqi,项目名称:holoviews,代码行数:9,代码来源:testcolumns.py

示例2: test_columns_sort_heterogeneous_string

# 需要导入模块: from holoviews import Columns [as 别名]
# 或者: from holoviews.Columns import sort [as 别名]
 def test_columns_sort_heterogeneous_string(self):
     columns = Columns(zip(self.keys1, self.values1),
                     kdims=self.kdims, vdims=self.vdims)
     keys =   [('F',12), ('M',10), ('M',16)]
     values = [(10, 0.8), (15, 0.8), (18, 0.6)]
     columns_sorted = Columns(zip(keys, values),
                              kdims=self.kdims, vdims=self.vdims)
     self.assertEqual(columns.sort(), columns_sorted)
开发者ID:stonebig,项目名称:holoviews,代码行数:10,代码来源:testcolumns.py

示例3: test_columns_sort_vdim

# 需要导入模块: from holoviews import Columns [as 别名]
# 或者: from holoviews.Columns import sort [as 别名]
 def test_columns_sort_vdim(self):
     columns = Columns(pd.DataFrame({'x': self.xs, 'y': -self.ys}),
                       kdims=['x'], vdims=['y'])
     columns_sorted = Columns(pd.DataFrame({'x': self.xs[::-1], 'y': -self.ys[::-1]}),
                              kdims=['x'], vdims=['y'])
     self.assertEqual(columns.sort('y'), columns_sorted)
开发者ID:stonebig,项目名称:holoviews,代码行数:8,代码来源:testcolumns.py

示例4: test_columns_sort_vdim_ht

# 需要导入模块: from holoviews import Columns [as 别名]
# 或者: from holoviews.Columns import sort [as 别名]
 def test_columns_sort_vdim_ht(self):
     columns = Columns({'x':self.xs, 'y':-self.ys},
                       kdims=['x'], vdims=['y'])
     columns_sorted = Columns({'x':self.xs[::-1], 'y':-self.ys[::-1]},
                              kdims=['x'], vdims=['y'])
     self.assertEqual(columns.sort('y'), columns_sorted)
开发者ID:pittmiqi,项目名称:holoviews,代码行数:8,代码来源:testcolumns.py

示例5: HeterogeneousColumnTypes

# 需要导入模块: from holoviews import Columns [as 别名]
# 或者: from holoviews.Columns import sort [as 别名]
class HeterogeneousColumnTypes(HomogeneousColumnTypes):
    """
    Tests for data formats that all columns to have varied types
    """

    def init_data(self):
        self.kdims = ['Gender', 'Age']
        self.vdims = ['Weight', 'Height']
        self.gender, self.age = ['M','M','F'], [10,16,12]
        self.weight, self.height = [15,18,10], [0.8,0.6,0.8]
        self.table = Columns({'Gender':self.gender, 'Age':self.age,
                              'Weight':self.weight, 'Height':self.height},
                             kdims=self.kdims, vdims=self.vdims)

        super(HeterogeneousColumnTypes, self).init_data()
        self.ys = np.linspace(0, 1, 11)
        self.zs = np.sin(self.xs)
        self.columns_ht = Columns({'x':self.xs, 'y':self.ys},
                                  kdims=['x'], vdims=['y'])

    # Test the constructor to be supported by all interfaces supporting
    # heterogeneous column types.

    def test_columns_ndelement_init_ht(self):
        "Tests support for heterogeneous NdElement (backwards compatibility)"
        columns = Columns(NdElement(zip(self.xs, self.ys), kdims=['x'], vdims=['y']))
        self.assertTrue(isinstance(columns.data, self.data_instance_type))

    def test_columns_dataframe_init_ht(self):
        "Tests support for heterogeneous DataFrames"
        if pd is None:
            raise SkipTest("Pandas not available")
        columns = Columns(pd.DataFrame({'x':self.xs, 'y':self.ys}), kdims=['x'], vdims=['y'])
        self.assertTrue(isinstance(columns.data, self.data_instance_type))

    # Test literal formats

    def test_columns_uniq_dimvals_ht(self):
        self.assertEqual(self.table.dimension_values('Gender', unique=True),
                         np.array(['M', 'F']))

    def test_columns_implicit_indexing_init(self):
        columns = Columns(self.ys, kdims=['x'], vdims=['y'])
        self.assertTrue(isinstance(columns.data, self.data_instance_type))

    def test_columns_tuple_init(self):
        columns = Columns((self.xs, self.ys), kdims=['x'], vdims=['y'])
        self.assertTrue(isinstance(columns.data, self.data_instance_type))

    def test_columns_simple_zip_init(self):
        columns = Columns(zip(self.xs, self.ys), kdims=['x'], vdims=['y'])
        self.assertTrue(isinstance(columns.data, self.data_instance_type))

    def test_columns_zip_init(self):
        columns = Columns(zip(self.gender, self.age,
                              self.weight, self.height),
                          kdims=self.kdims, vdims=self.vdims)
        self.assertTrue(isinstance(columns.data, self.data_instance_type))

    def test_columns_odict_init(self):
        columns = Columns(OrderedDict(zip(self.xs, self.ys)), kdims=['A'], vdims=['B'])
        self.assertTrue(isinstance(columns.data, self.data_instance_type))

    def test_columns_dict_init(self):
        columns = Columns(dict(zip(self.xs, self.ys)), kdims=['A'], vdims=['B'])
        self.assertTrue(isinstance(columns.data, self.data_instance_type))

    # Operations

    def test_columns_sort_vdim_ht(self):
        columns = Columns({'x':self.xs, 'y':-self.ys},
                          kdims=['x'], vdims=['y'])
        columns_sorted = Columns({'x':self.xs[::-1], 'y':-self.ys[::-1]},
                                 kdims=['x'], vdims=['y'])
        self.assertEqual(columns.sort('y'), columns_sorted)

    def test_columns_sort_string_ht(self):
        columns_sorted = Columns({'Gender':['F','M','M'], 'Age':[12,10,16],
                                  'Weight':[10,15,18], 'Height':[0.8,0.8,0.6]},
                                 kdims=self.kdims, vdims=self.vdims)
        self.assertEqual(self.table.sort(), columns_sorted)

    def test_columns_sample_ht(self):
        samples = self.columns_ht.sample([0, 5, 10]).dimension_values('y')
        self.assertEqual(samples, np.array([0, 0.5, 1]))

    def test_columns_reduce_ht(self):
        reduced = Columns({'Age':self.age, 'Weight':self.weight, 'Height':self.height},
                          kdims=self.kdims[1:], vdims=self.vdims)
        self.assertEqual(self.table.reduce(['Gender'], np.mean), reduced)

    def test_columns_1D_reduce_ht(self):
        self.assertEqual(self.columns_ht.reduce('x', np.mean), np.float64(0.5))

    def test_columns_2D_reduce_ht(self):
        reduced = Columns({'Weight':[14.333333333333334], 'Height':[0.73333333333333339]},
                          kdims=[], vdims=self.vdims)
        self.assertEqual(self.table.reduce(function=np.mean), reduced)

    def test_columns_2D_partial_reduce_ht(self):
#.........这里部分代码省略.........
开发者ID:pittmiqi,项目名称:holoviews,代码行数:103,代码来源:testcolumns.py

示例6: GridColumnsTest

# 需要导入模块: from holoviews import Columns [as 别名]
# 或者: from holoviews.Columns import sort [as 别名]
class GridColumnsTest(HomogeneousColumnTypes, ComparisonTestCase):
    """
    Test of the NdColumns interface (mostly for backwards compatibility)
    """

    def setUp(self):
        self.restore_datatype = Columns.datatype
        Columns.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.columns_hm = Columns((self.xs, self.y_ints),
                                  kdims=['x'], vdims=['y'])

    def test_columns_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):
            Columns(np.column_stack([self.xs, self.xs_2]),
                    kdims=['x'], vdims=['x2'])

    def test_columns_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):
            Columns(pd.DataFrame({'x':self.xs, 'x2':self.xs_2}),
                    kdims=['x'], vdims=['x2'])

    def test_columns_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):
            Columns(NdElement(zip(self.xs, self.xs_2),
                              kdims=['x'], vdims=['x2']))

    def test_columns_2D_aggregate_partial_hm(self):
        array = np.random.rand(11, 11)
        columns = Columns({'x':self.xs, 'y':self.y_ints, 'z': array},
                          kdims=['x', 'y'], vdims=['z'])
        self.assertEqual(columns.aggregate(['x'], np.mean),
                         Columns({'x':self.xs, 'z': np.mean(array, axis=1)},
                                 kdims=['x'], vdims=['z']))

    def test_columns_2D_reduce_hm(self):
        array = np.random.rand(11, 11)
        columns = Columns({'x':self.xs, 'y':self.y_ints, 'z': array},
                          kdims=['x', 'y'], vdims=['z'])
        self.assertEqual(np.array(columns.reduce(['x', 'y'], np.mean)),
                         np.mean(array))

    def test_columns_add_dimensions_value_hm(self):
        with self.assertRaisesRegexp(Exception, 'Cannot add key dimension to a dense representation.'):
            self.columns_hm.add_dimension('z', 1, 0)

    def test_columns_add_dimensions_values_hm(self):
        table =  self.columns_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_columns_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.columns_hm.sort('y')


    def test_columns_groupby(self):
        self.assertEqual(self.columns_hm.groupby('x').keys(), list(self.xs))
开发者ID:corinnebosley,项目名称:holoviews,代码行数:80,代码来源:testcolumns.py


注:本文中的holoviews.Columns.sort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。