group.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:exdir 作者: CINPLA 项目源码 文件源码
def require_dataset(self, name, shape=None, dtype=None, exact=False,
                        data=None, fillvalue=None):
        if name not in self:
            return self.create_dataset(
                name,
                shape=shape,
                dtype=dtype,
                data=data,
                fillvalue=fillvalue
            )

        current_object = self[name]

        if not isinstance(current_object, ds.Dataset):
            raise TypeError(
                "Incompatible object already exists: {}".format(
                    current_object.__class__.__name__
                )
            )

        data, attrs, meta = ds._prepare_write(data, self.plugin_manager.dataset_plugins.write_order)

        # TODO verify proper attributes

        _assert_data_shape_dtype_match(data, shape, dtype)
        shape, dtype = _data_to_shape_and_dtype(data, shape, dtype)

        if not np.array_equal(shape, current_object.shape):
            raise TypeError(
                "Shapes do not match (existing {} vs "
                "new {})".format(current_object.shape, shape)
            )

        if dtype != current_object.dtype:
            if exact:
                raise TypeError(
                    "Datatypes do not exactly match "
                    "existing {} vs new {})".format(current_object.dtype, dtype)
                )

            if not np.can_cast(dtype, current_object.dtype):
                raise TypeError(
                    "Cannot safely cast from {} to {}".format(
                        dtype,
                        current_object.dtype
                    )
                )

        return current_object
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号