Skip to content

Commit

Permalink
permit_dask -> delayed in NanoEventsFactory.from_X
Browse files Browse the repository at this point in the history
  • Loading branch information
lgray committed Nov 9, 2023
1 parent d2d1cfc commit 57474ff
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 25 deletions.
20 changes: 11 additions & 9 deletions src/coffea/nanoevents/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def from_root(
access_log=None,
iteritems_options={},
use_ak_forth=True,
permit_dask=True,
delayed=True,
):
"""Quickly build NanoEvents from a root file
Expand Down Expand Up @@ -277,8 +277,8 @@ def from_root(
Pass a list instance to record which branches were lazily accessed by this instance
use_ak_forth:
Toggle using awkward_forth to interpret branches in root file.
permit_dask:
Allow nanoevents to use dask as a backend.
delayed:
Nanoevents will use dask as a backend to construct a delayed task graph representing your analysis.
"""

if treepath is not uproot._util.unset and not isinstance(
Expand All @@ -291,7 +291,7 @@ def from_root(
)

if (
permit_dask
delayed
and not isinstance(schemaclass, FunctionType)
and schemaclass.__dask_capable__
):
Expand Down Expand Up @@ -326,7 +326,7 @@ def from_root(
**uproot_options,
)
return cls(map_schema, opener, None, cache=None, is_dask=True)
elif permit_dask and not schemaclass.__dask_capable__:
elif delayed and not schemaclass.__dask_capable__:
warnings.warn(
f"{schemaclass} is not dask capable despite allowing dask, generating non-dask nanoevents"
)
Expand Down Expand Up @@ -380,7 +380,7 @@ def from_root(
def from_parquet(
cls,
file,
treepath="/Events",
treepath=uproot._util.unset,
entry_start=None,
entry_stop=None,
runtime_cache=None,
Expand All @@ -390,7 +390,7 @@ def from_parquet(
parquet_options={},
skyhook_options={},
access_log=None,
permit_dask=False,
delayed=True,
):
"""Quickly build NanoEvents from a parquet file
Expand Down Expand Up @@ -419,6 +419,8 @@ def from_parquet(
Any options to pass to ``pyarrow.parquet.ParquetFile``
access_log : list, optional
Pass a list instance to record which branches were lazily accessed by this instance
delayed:
Nanoevents will use dask as a backend to construct a delayed task graph representing your analysis.
"""
import pyarrow
import pyarrow.dataset as ds
Expand All @@ -434,7 +436,7 @@ def from_parquet(
)

if (
permit_dask
delayed
and not isinstance(schemaclass, FunctionType)
and schemaclass.__dask_capable__
):
Expand All @@ -453,7 +455,7 @@ def from_parquet(
else:
raise TypeError("Invalid file type (%s)" % (str(type(file))))
return cls(map_schema, opener, None, cache=None, is_dask=True)
elif permit_dask and not schemaclass.__dask_capable__:
elif delayed and not schemaclass.__dask_capable__:
warnings.warn(
f"{schemaclass} is not dask capable despite allowing dask, generating non-dask nanoevents"
)
Expand Down
2 changes: 1 addition & 1 deletion src/coffea/processor/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,7 @@ def _work_function(
schemaclass=schema,
metadata=metadata,
access_log=materialized,
permit_dask=True,
delayed=True,
)
events = factory.events()[item.entrystart : item.entrystop]
elif format == "parquet":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_analysis_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{os.path.abspath(fname): "Events"},
schemaclass=NanoAODSchema,
metadata={"dataset": "DYJets"},
permit_dask=False,
delayed=False,
).events()
dakevents = NanoEventsFactory.from_root(
{os.path.abspath(fname): "Events"},
Expand Down
1 change: 0 additions & 1 deletion tests/test_fix823.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def test_explicit_delete_after_assign():
{testfile: "Events"},
metadata={"dataset": "nano_dy"},
schemaclass=NanoAODSchema,
permit_dask=True,
).events()

genpart = events["GenPart"]
Expand Down
1 change: 0 additions & 1 deletion tests/test_jetmet_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,6 @@ def test_corrected_jets_factory(optimization_enabled):
events = NanoEventsFactory.from_root(
{os.path.abspath("tests/samples/nano_dy.root"): "Events"},
metadata={},
permit_dask=True,
).events()

jec_stack_names = [
Expand Down
2 changes: 0 additions & 2 deletions tests/test_lookup_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ def test_rochester():
# test against nanoaod
events = NanoEventsFactory.from_root(
{os.path.abspath("tests/samples/nano_dimuon.root"): "Events"},
permit_dask=True,
).events()

data_k = rochester.kScaleDT(
Expand All @@ -406,7 +405,6 @@ def test_rochester():
# test against mc
events = NanoEventsFactory.from_root(
{os.path.abspath("tests/samples/nano_dy.root"): "Events"},
permit_dask=True,
).events()

hasgen = ~np.isnan(ak.fill_none(events.Muon.matched_gen.pt, np.nan))
Expand Down
14 changes: 8 additions & 6 deletions tests/test_nanoevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_read_nanomc(suffix):
factory = getattr(NanoEventsFactory, f"from_{suffix}")(
{path: "Events"},
schemaclass=nanoversion,
permit_dask=False,
delayed=False,
)
events = factory.events()

Expand Down Expand Up @@ -138,7 +138,7 @@ def test_read_from_uri(suffix):
factory = getattr(NanoEventsFactory, f"from_{suffix}")(
{path: "Events"},
schemaclass=nanoversion,
permit_dask=False,
delayed=False,
)
events = factory.events()

Expand All @@ -153,7 +153,7 @@ def test_read_nanodata(suffix):
factory = getattr(NanoEventsFactory, f"from_{suffix}")(
{path: "Events"},
schemaclass=nanoversion,
permit_dask=False,
delayed=False,
)
events = factory.events()

Expand All @@ -165,7 +165,7 @@ def test_missing_eventIds_error():
path = os.path.abspath("tests/samples/missing_luminosityBlock.root") + ":Events"
with pytest.raises(RuntimeError):
factory = NanoEventsFactory.from_root(
path, schemaclass=NanoAODSchema, permit_dask=False
path, schemaclass=NanoAODSchema, delayed=False
)
factory.events()

Expand All @@ -177,7 +177,7 @@ def test_missing_eventIds_warning():
):
NanoAODSchema.error_missing_event_ids = False
factory = NanoEventsFactory.from_root(
path, schemaclass=NanoAODSchema, permit_dask=False
path, schemaclass=NanoAODSchema, delayed=False
)
factory.events()

Expand All @@ -186,6 +186,8 @@ def test_missing_eventIds_warning_dask():
path = os.path.abspath("tests/samples/missing_luminosityBlock.root") + ":Events"
NanoAODSchema.error_missing_event_ids = False
events = NanoEventsFactory.from_root(
path, schemaclass=NanoAODSchema, permit_dask=True
path,
schemaclass=NanoAODSchema,
delayed=True,
).events()
events.Muon.pt.compute(scheduler="processes")
4 changes: 3 additions & 1 deletion tests/test_nanoevents_delphes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
def _events():
path = os.path.abspath("tests/samples/delphes.root")
factory = NanoEventsFactory.from_root(
{path: "Delphes"}, schemaclass=DelphesSchema, permit_dask=True
{path: "Delphes"},
schemaclass=DelphesSchema,
delayed=True,
)
return factory.events()

Expand Down
4 changes: 3 additions & 1 deletion tests/test_nanoevents_pfnano.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
def events():
path = os.path.abspath("tests/samples/pfnano.root")
events = NanoEventsFactory.from_root(
{path: "Events"}, schemaclass=PFNanoAODSchema, permit_dask=True
{path: "Events"},
schemaclass=PFNanoAODSchema,
delayed=True,
).events()
return events

Expand Down
2 changes: 1 addition & 1 deletion tests/test_nanoevents_physlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def _events():
factory = NanoEventsFactory.from_root(
{path: "CollectionTree"},
schemaclass=PHYSLITESchema,
permit_dask=True,
delayed=True,
)
return factory.events()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_nanoevents_treemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def events():
path = os.path.abspath("tests/samples/treemaker.root")
events = NanoEventsFactory.from_root(
{path: "PreSelection"}, schemaclass=TreeMakerSchema, permit_dask=True
{path: "PreSelection"}, schemaclass=TreeMakerSchema, delayed=True
).events()
return events

Expand Down

0 comments on commit 57474ff

Please sign in to comment.