Skip to content

Commit e76fdbb

Browse files
committed
fix s3 source
1 parent 307a5ab commit e76fdbb

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/uproot/source/http.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@ class HTTPSource(uproot.source.chunk.Source):
563563
ResourceClass = HTTPResource
564564

565565
def __init__(self, file_path: str, **options):
566+
options = dict(uproot.reading.open.defaults, **options)
567+
566568
self._num_fallback_workers = options["num_fallback_workers"]
567569
self._timeout = options["timeout"]
568570
self._num_requests = 0
@@ -607,7 +609,7 @@ def __repr__(self):
607609
if len(self._file_path) > 10:
608610
path = repr("..." + self._file_path[-10:])
609611
fallback = ""
610-
if self._fallback is not None:
612+
if hasattr(self, "_fallback") and self._fallback is not None:
611613
fallback = " with fallback"
612614
return f"<{type(self).__name__} {path}{fallback} at 0x{id(self):012x}>"
613615

src/uproot/source/s3.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def __init__(
4242
):
4343
Minio = uproot.extras.Minio_client()
4444

45+
self._file_path = file_path
4546
if access_key is None:
4647
access_key = os.environ.get(
4748
"S3_ACCESS_KEY", os.environ.get("AWS_ACCESS_KEY_ID", None)

tests/test_0916_read_from_s3.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@
99

1010
@pytest.mark.network
1111
def test_s3_fail():
12-
with pytest.raises(Exception):
13-
with uproot.source.http.S3Source(
12+
with pytest.raises(FileNotFoundError):
13+
with uproot.source.s3.S3Source(
1414
"s3://pivarski-princeton/does-not-exist", timeout=0.1
1515
) as source:
16-
tobytes(source.chunk(0, 100).raw_data)
16+
uproot._util.tobytes(source.chunk(0, 100).raw_data)
1717

1818

1919
@pytest.mark.network
2020
def test_read_s3():
2121
with uproot.open(
22-
"s3://pivarski-princeton/pythia_ppZee_run17emb.picoDst.root:PicoDst"
22+
"s3://pivarski-princeton/pythia_ppZee_run17emb.picoDst.root:PicoDst",
23+
handler=uproot.source.s3.S3Source,
2324
) as f:
2425
data = f["Event/Event.mEventId"].array(library="np")
2526
assert len(data) == 8004

0 commit comments

Comments
 (0)