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)
评论列表
文章目录