Skip to content

Commit

Permalink
fix s3 source
Browse files Browse the repository at this point in the history
  • Loading branch information
lobis committed Nov 15, 2023
1 parent 307a5ab commit e76fdbb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/uproot/source/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ class HTTPSource(uproot.source.chunk.Source):
ResourceClass = HTTPResource

def __init__(self, file_path: str, **options):
options = dict(uproot.reading.open.defaults, **options)

self._num_fallback_workers = options["num_fallback_workers"]
self._timeout = options["timeout"]
self._num_requests = 0
Expand Down Expand Up @@ -607,7 +609,7 @@ def __repr__(self):
if len(self._file_path) > 10:
path = repr("..." + self._file_path[-10:])
fallback = ""
if self._fallback is not None:
if hasattr(self, "_fallback") and self._fallback is not None:
fallback = " with fallback"
return f"<{type(self).__name__} {path}{fallback} at 0x{id(self):012x}>"

Expand Down
1 change: 1 addition & 0 deletions src/uproot/source/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(
):
Minio = uproot.extras.Minio_client()

self._file_path = file_path
if access_key is None:
access_key = os.environ.get(
"S3_ACCESS_KEY", os.environ.get("AWS_ACCESS_KEY_ID", None)
Expand Down
9 changes: 5 additions & 4 deletions tests/test_0916_read_from_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@

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


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

0 comments on commit e76fdbb

Please sign in to comment.