本文整理汇总了Python中chaco.api.ArrayDataSource.__getstate__方法的典型用法代码示例。如果您正苦于以下问题:Python ArrayDataSource.__getstate__方法的具体用法?Python ArrayDataSource.__getstate__怎么用?Python ArrayDataSource.__getstate__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chaco.api.ArrayDataSource
的用法示例。
在下文中一共展示了ArrayDataSource.__getstate__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ArrayDataSourceTestCase
# 需要导入模块: from chaco.api import ArrayDataSource [as 别名]
# 或者: from chaco.api.ArrayDataSource import __getstate__ [as 别名]
#.........这里部分代码省略.........
data_source = ArrayDataSource(array([np.nan, 3, 0, 9, np.nan, 18, 3]))
bounds = data_source.get_bounds()
self.assertEqual(bounds, (0, 18))
def test_bounds_negative_inf(self):
data_source = ArrayDataSource(array([12, 3, -np.inf, 9, 2, 18, 3]))
bounds = data_source.get_bounds()
self.assertEqual(bounds, (-np.inf, 18))
def test_bounds_positive_inf(self):
data_source = ArrayDataSource(array([12, 3, 0, 9, 2, np.inf, 3]))
bounds = data_source.get_bounds()
self.assertEqual(bounds, (0, np.inf))
def test_bounds_negative_positive_inf(self):
data_source = ArrayDataSource(array([12, 3, -np.inf, 9, 2, np.inf, 3]))
bounds = data_source.get_bounds()
self.assertEqual(bounds, (-np.inf, np.inf))
def test_bounds_non_numeric(self):
myarray = np.array([u'abc', u'foo', u'bar', u'def'], dtype=unicode)
data_source = ArrayDataSource(myarray)
bounds = data_source.get_bounds()
self.assertEqual(bounds, (u'abc', u'def'))
def test_data_size(self):
# We know that ArrayDataTestCase always returns the exact length of
# its data
myarray = arange(913)
data_source = ArrayDataSource(myarray)
self.assertEqual(len(myarray), data_source.get_size())
def test_reverse_map(self):
# sort_order ascending
myarray = arange(10)
data_source = ArrayDataSource(myarray, sort_order='ascending')
self.assertEqual(data_source.reverse_map(4.0), 4)
# sort_order descending
myarray = arange(10)[::-1]
data_source = ArrayDataSource(myarray, sort_order='descending')
self.assertEqual(data_source.reverse_map(4.0), 5)
# sort_order none
myarray = array([12, 3, 0, 9, 2, 18, 3])
data_source = ArrayDataSource(myarray, sort_order='none')
with self.assertRaises(NotImplementedError):
data_source.reverse_map(3)
def test_metadata(self):
self.assertEqual(self.data_source.metadata,
{'annotations': [], 'selections': []})
def test_metadata_changed(self):
with self.assertTraitChanges(self.data_source, 'metadata_changed',
count=1):
self.data_source.metadata = {'new_metadata': True}
def test_metadata_items_changed(self):
with self.assertTraitChanges(self.data_source, 'metadata_changed',
count=1):
self.data_source.metadata['new_metadata'] = True
def test_serialization_state(self):
state = self.data_source.__getstate__()
self.assertNotIn('value_dimension', state)
self.assertNotIn('index_dimension', state)
self.assertNotIn('persist_data', state)
@unittest.skip("persist_data probably shouldn't be persisted")
def test_serialization_state_no_persist(self):
self.data_source.persist_data = False
state = self.data_source.__getstate__()
self.assertNotIn('value_dimension', state)
self.assertNotIn('index_dimension', state)
self.assertNotIn('persist_data', state)
for key in ["_data", "_cached_mask", "_cached_bounds", "_min_index",
"_max_index"]:
self.assertIn(key, state)
@unittest.skip("I think this is just broken")
def test_serialization_post_load(self):
self.data_source.set_mask(self.mymask)
pickled_data_source = pickle.dumps(self.data_source)
unpickled_data_source = pickle.loads(pickled_data_source)
unpickled_data_source._post_load()
self.assertEqual(unpickled_data_source._cached_bounds, ())
self.assertEqual(unpickled_data_source._cached_mask, None)
assert_array_equal(self.data_source.get_data(),
unpickled_data_source.get_data())
mask = unpickled_data_source.get_data_mask()[1]
assert_array_equal(mask, ones(10))