metadata.py 文件源码

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

项目:qiime2 作者: qiime2 项目源码 文件源码
def _validate_pandas_index(index, label):
    # `/` and `\0` aren't permitted because they are invalid filename
    # characters on *nix filesystems. The remaining values aren't permitted
    # because they *could* be misinterpreted by a shell (e.g. `*`, `|`).
    illegal_chars = ['/', '\0', '\\', '*', '<', '>', '?', '|', '$']
    chars_for_msg = ", ".join("%r" % i for i in illegal_chars)
    illegal_chars = set(illegal_chars)

    # First check the index dtype and ensure there are no null values
    if index.dtype_str not in ['object', 'str'] or pd.isnull(index).any():
        msg = "Non-string Metadata %s values detected" % label
        raise ValueError(invalid_metadata_template % msg)

    # Then check for invalid characters along index
    for value in index:
        if not value or illegal_chars & set(value):
            msg = "Invalid characters (e.g. %s) or empty ID detected in " \
                  "metadata %s: %r" % (chars_for_msg, label, value)
            raise ValueError(invalid_metadata_template % msg)

    # Finally, ensure unique values along index
    if len(index) != len(set(index)):
        msg = "Duplicate Metadata %s values detected" % label
        raise ValueError(invalid_metadata_template % msg)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号