Skip to content

Commit 8290c4c

Browse files
lobisjpivarski
andauthored
fix: multithreaded file source breaks interpretation (#1036)
* test passes * add skeleton for test * test different handlers * download file from data repo fork * download file from data repo fork * reproducer test * revert changes to fsspec source * aiohttp skip * test mt source * rerun on socket failure * check data length * remove problematic interpretation * skip branch if it has sub-branches * rename test * pass failing test * simplified * check for AsGrouped interpretation instead * fsspec-xrootd is not a direct Uproot dependency (fsspec itself will be) * Same result, but more straightforward logic. * use another test file with similar structure to avoid adding new test file --------- Co-authored-by: Jim Pivarski <[email protected]>
1 parent c956761 commit 8290c4c

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

.github/workflows/build-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767

6868
- name: Run pytest
6969
run: |
70-
python -m pytest -vv tests --reruns 3 --reruns-delay 30 --only-rerun "(?i)http|timeout|connection"
70+
python -m pytest -vv tests --reruns 3 --reruns-delay 30 --only-rerun "(?i)http|timeout|connection|socket"
7171
7272
vanilla-build:
7373
strategy:
@@ -91,4 +91,4 @@ jobs:
9191

9292
- name: Run pytest
9393
run: |
94-
python -m pytest -vv tests --reruns 3 --reruns-delay 30 --only-rerun "(?i)http|timeout|connection"
94+
python -m pytest -vv tests --reruns 3 --reruns-delay 30 --only-rerun "(?i)http|timeout|connection|socket"

src/uproot/behaviors/TBranch.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
objects themselves.
1212
"""
1313

14-
1514
import queue
1615
import re
1716
import sys
@@ -21,6 +20,7 @@
2120
import numpy
2221

2322
import uproot
23+
import uproot.interpretation.grouped
2424
import uproot.language.python
2525
from uproot._util import no_filter
2626

@@ -1809,7 +1809,10 @@ def get_from_cache(branchname, interpretation):
18091809
checked = set()
18101810
for _, context in expression_context:
18111811
for branch in context["branches"]:
1812-
if branch.cache_key not in checked:
1812+
if branch.cache_key not in checked and not isinstance(
1813+
branchid_interpretation[branch.cache_key],
1814+
uproot.interpretation.grouped.AsGrouped,
1815+
):
18131816
checked.add(branch.cache_key)
18141817
for (
18151818
basket_num,

tests/test_0692_fsspec_reading.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import pytest
44
import uproot
55
import uproot.source.fsspec
6+
import uproot.source.file
7+
import uproot.source.xrootd
8+
import uproot.source.s3
69

710
import skhep_testdata
811
import queue
@@ -123,6 +126,7 @@ def test_open_fsspec_ssh(handler):
123126
)
124127
def test_open_fsspec_xrootd(handler):
125128
pytest.importorskip("XRootD")
129+
pytest.importorskip("fsspec_xrootd")
126130
with uproot.open(
127131
"root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root",
128132
handler=handler,
@@ -208,3 +212,27 @@ def test_fsspec_zip(tmp_path):
208212
) as branch:
209213
data = branch.array(library="np")
210214
assert len(data) == 40
215+
216+
217+
# https://github.com/scikit-hep/uproot5/issues/1035
218+
@pytest.mark.parametrize(
219+
"handler",
220+
[
221+
uproot.source.file.MemmapSource,
222+
uproot.source.file.MultithreadedFileSource,
223+
uproot.source.fsspec.FSSpecSource,
224+
None,
225+
],
226+
)
227+
def test_issue_1035(handler):
228+
with uproot.open(
229+
skhep_testdata.data_path("uproot-issue-798.root"),
230+
handler=handler,
231+
use_threads=True,
232+
num_workers=10,
233+
) as f:
234+
for _ in range(25): # intermittent failure
235+
tree = f["CollectionTree"]
236+
branch = tree["MuonSpectrometerTrackParticlesAuxDyn.truthParticleLink"]
237+
data = branch.array()
238+
assert len(data) == 40

0 commit comments

Comments
 (0)