Skip to content

Commit 637c160

Browse files
author
Matthew Hoffman
committed
Add unicode escape to handle parsing string_to_dict in Windows paths
1 parent 8cc0186 commit 637c160

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/datasets/utils/py_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def string_to_dict(string: str, pattern: str) -> Optional[dict[str, str]]:
180180
Optional[dict[str, str]]: dictionary of variable -> value, retrieved from the input using the pattern, or
181181
`None` if the string does not match the pattern.
182182
"""
183+
pattern = pattern.encode("unicode_escape").decode("utf-8") # C:\\Users -> C:\\\\Users for Windows paths
183184
pattern = re.sub(r"{([^:}]+)(?::[^}]+)?}", r"{\1}", pattern) # remove format specifiers, e.g. {rank:05d} -> {rank}
184185
regex = re.sub(r"{(.+?)}", r"(?P<_\1>.+)", pattern)
185186
result = re.search(regex, string)

0 commit comments

Comments
 (0)