Fix path separator mismatch in open_mfdatatree on Windows - #87
Open
ClaudioStrumia wants to merge 1 commit into
Open
Fix path separator mismatch in open_mfdatatree on Windows#87ClaudioStrumia wants to merge 1 commit into
ClaudioStrumia wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows,
glob.glob()returns file paths using backslashes (\) asseparators, while the path descriptor passed to
open_mfdatatree(and theregex built from it) assumes forward slashes (
/).This mismatch causes two issues:
pathsfails to match the backslash-separatedfilenames returned by
glob, sinceregex.match(fname)returnsNoneand calling
.group(field)on it raises anAttributeError.(e.g.
C:\Users\...) can be interpreted byre.compileas invalidregex escape sequences (e.g.
\Uis parsed as the start of an8-digit unicode escape), raising a
re.PatternError: incomplete escape.Fix
Both the path descriptor (
paths) and the paths returned byglob(
fnames) are now normalized to use forward slashes viaPath(...).as_posix(). This ensures the regex is always built and matchedagainst POSIX-style paths, regardless of the OS.
On POSIX systems (Linux/macOS) this is a no-op, since paths already use
forward slashes there.
Testing
Ran the full test suite on Windows before and after the fix. The following
three tests, which were failing before the fix with
re.PatternError: incomplete escape \U at position 2, now pass:tests/test_routines.py::TestOpen::test_open_multiple_file_treetests/test_routines.py::TestOpenMFDataTree::test_one_level_depthtests/test_routines.py::TestOpenMFDataTree::test_two_level_depthNo new test failures were introduced (remaining failures are pre-existing
and unrelated to this change, e.g.
os.sysconfnot available on Windows,multiprocessing/shared-memory handling, and
:not being a valid characterin Windows filenames).