Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/scikit-hep/uproot4
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski committed Nov 6, 2020
2 parents aad57b3 + d473eb2 commit 95af9c8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
23 changes: 23 additions & 0 deletions tests/test_0182-complain-about-missing-files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE

from __future__ import absolute_import

import numpy
import pytest
import skhep_testdata

import uproot4


def test():
one = skhep_testdata.data_path("uproot-sample-6.16.00-uncompressed.root")
two = skhep_testdata.data_path("uproot-sample-6.18.00-uncompressed.root")
bad = one.replace(".root", "-DOES-NOT-EXIST.root")
okay = one.replace(".root", "-DOES-NOT-EXIST-*.root")

assert len(list(uproot4.iterate([one, two], step_size="1 TB"))) == 2

with pytest.raises(uproot4._util._FileNotFoundError):
list(uproot4.iterate([one, two, bad]))

assert len(list(uproot4.iterate([one, two, okay], step_size="1 TB"))) == 2
41 changes: 23 additions & 18 deletions uproot4/behaviors/TBranch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2797,6 +2797,7 @@ def _keys_deep(hasbranches):


_regularize_files_braces = re.compile(r"{([^}]*,)*([^}]*)}")
_regularize_files_isglob = re.compile(r"[\*\?\[\]{}]")


def _regularize_files_inner(files, parse_colon, counter):
Expand All @@ -2819,25 +2820,29 @@ def _regularize_files_inner(files, parse_colon, counter):

else:
expanded = os.path.expanduser(file_path)
matches = list(_regularize_files_braces.finditer(expanded))
if len(matches) == 0:
results = [expanded]
if _regularize_files_isglob.search(expanded) is None:
yield file_path, object_path

else:
results = []
for combination in itertools.product(
*[match.group(0)[1:-1].split(",") for match in matches]
):
tmp = expanded
for c, m in list(zip(combination, matches))[::-1]:
tmp = tmp[: m.span()[0]] + c + tmp[m.span()[1] :]
results.append(tmp)

seen = set()
for result in results:
for match in glob.glob(result):
if match not in seen:
yield match, object_path
seen.add(match)
matches = list(_regularize_files_braces.finditer(expanded))
if len(matches) == 0:
results = [expanded]
else:
results = []
for combination in itertools.product(
*[match.group(0)[1:-1].split(",") for match in matches]
):
tmp = expanded
for c, m in list(zip(combination, matches))[::-1]:
tmp = tmp[: m.span()[0]] + c + tmp[m.span()[1] :]
results.append(tmp)

seen = set()
for result in results:
for match in glob.glob(result):
if match not in seen:
yield match, object_path
seen.add(match)

elif isinstance(files, HasBranches):
yield files, None
Expand Down

0 comments on commit 95af9c8

Please sign in to comment.