本文整理汇总了Python中iris._data_manager.DataManager._realised_dtype_setter方法的典型用法代码示例。如果您正苦于以下问题:Python DataManager._realised_dtype_setter方法的具体用法?Python DataManager._realised_dtype_setter怎么用?Python DataManager._realised_dtype_setter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iris._data_manager.DataManager
的用法示例。
在下文中一共展示了DataManager._realised_dtype_setter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test__realised_dtype_setter
# 需要导入模块: from iris._data_manager import DataManager [as 别名]
# 或者: from iris._data_manager.DataManager import _realised_dtype_setter [as 别名]
class Test__realised_dtype_setter(tests.IrisTest):
def setUp(self):
self.real_array = np.array(0.0)
self.lazy_array = as_lazy_data(self.real_array)
self.dm = DataManager(self.lazy_array)
def test_lazy_with_none(self):
self.assertIsNone(self.dm._realised_dtype)
self.dm._realised_dtype_setter(None)
self.assertIsNone(self.dm._realised_dtype)
def test_real_with_none(self):
self.dm._lazy_array = None
self.dm._real_array = self.real_array
self.assertIsNone(self.dm._realised_dtype)
self.dm._realised_dtype_setter(None)
self.assertIsNone(self.dm._realised_dtype)
def test_real_with_same_dtype(self):
self.dm._lazy_array = None
self.dm._real_array = self.real_array
self.assertIsNone(self.dm._realised_dtype)
self.dm._realised_dtype_setter(self.dm.dtype)
self.assertIsNone(self.dm._realised_dtype)
def test_lazy_with_same_dtype(self):
self.assertIsNone(self.dm._realised_dtype)
self.dm._realised_dtype_setter(self.dm.dtype)
self.assertIsNone(self.dm._realised_dtype)
def test_real_array_failure(self):
self.dm._lazy_array = None
self.dm._real_array = self.real_array
self.assertIsNone(self.dm._realised_dtype)
emsg = 'Cannot set realised dtype, no lazy data is available'
with self.assertRaisesRegexp(ValueError, emsg):
self.dm._realised_dtype_setter(np.dtype('int16'))
def test_invalid_realised_dtype(self):
emsg = ("Can only cast lazy data to an integer or boolean "
"dtype, got dtype\('float32'\)")
with self.assertRaisesRegexp(ValueError, emsg):
self.dm._realised_dtype_setter(np.dtype('float32'))
def test_lazy_with_realised_dtype(self):
dtypes = (np.dtype('bool'), np.dtype('int16'), np.dtype('uint16'))
for dtype in dtypes:
self.dm._realised_dtype = None
self.dm._realised_dtype_setter(dtype)
self.assertEqual(self.dm._realised_dtype, dtype)
def test_lazy_with_realised_dtype__lazy_dtype_failure(self):
self.dm._lazy_array = self.lazy_array.astype(np.dtype('int64'))
emsg = ("Cannot set realised dtype for lazy data "
"with dtype\('int64'\)")
with self.assertRaisesRegexp(ValueError, emsg):
self.dm._realised_dtype_setter(np.dtype('int16'))
def test_lazy_replace_with_none(self):
self.assertIsNone(self.dm._realised_dtype)
dtype = np.dtype('int16')
self.dm._realised_dtype_setter(dtype)
self.assertEqual(self.dm._realised_dtype, dtype)
self.dm._realised_dtype_setter(None)
self.assertIsNone(self.dm._realised_dtype)