Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: s3 source options and repr #1024

Merged
merged 7 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions 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 getattr(self, "_fallback", None) is not None:
fallback = " with fallback"
return f"<{type(self).__name__} {path}{fallback} at 0x{id(self):012x}>"

Expand Down Expand Up @@ -759,7 +761,7 @@ def _open(self):
self._executor = uproot.source.futures.ResourceThreadPoolExecutor(
[
HTTPResource(self._file_path, self._timeout)
for x in range(self._num_workers)
for _ in range(self._num_workers)
]
)
else:
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
pytest.importorskip("minio")


@pytest.mark.skip("https://github.com/scikit-hep/uproot5/pull/1012")
@pytest.mark.network
def test_s3_fail():
with pytest.raises(Exception):
with uproot.source.http.S3Source(
# TODO: fix this! Something not closing properly.
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
Loading