Skip to content

Commit

Permalink
naming, simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasdavis committed Nov 30, 2023
1 parent ed9b32a commit 25558bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
22 changes: 7 additions & 15 deletions src/dask_awkward/layers/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ def mock_empty(self, backend: BackendT = "cpu") -> AwkwardArray:
)


def io_func_reor_wrapped(func: ImplementsIOFunction) -> bool:
return hasattr(func, "__reor_wrapped__")
def io_func_rer_wrapped(func: ImplementsIOFunction) -> bool:
return hasattr(func, "__rer_wrapped__")


def maybe_unwrap(func: Callable) -> Callable:
if io_func_reor_wrapped(func):
return func.__reor_wrapped__ # type: ignore
if io_func_rer_wrapped(func):
return func.__rer_wrapped__ # type: ignore
return func


Expand Down Expand Up @@ -242,7 +242,7 @@ def prepare_for_projection(self) -> tuple[AwkwardInputLayer, TypeTracerReport, T
ImplementsProjection, fn
).prepare_for_projection()

if io_func_reor_wrapped(self.io_func):
if io_func_rer_wrapped(self.io_func):
new_return = (new_meta_array, type(new_meta_array)([]))
else:
new_return = new_meta_array
Expand All @@ -267,16 +267,8 @@ def project(
fn = maybe_unwrap(self.io_func)
io_func = cast(ImplementsProjection, fn).project(report=report, state=state)

if io_func_reor_wrapped(self.io_func):
from dask_awkward.lib.io.io import return_empty_on_raise

io_func = return_empty_on_raise(
io_func,
allowed_exceptions=self.io_func.allowed_exceptions, # type: ignore
backend=self.io_func.backend, # type: ignore
success_callback=self.io_func.success_callback, # type: ignore
failure_callback=self.io_func.failure_callback, # type: ignore
)
if io_func_rer_wrapped(self.io_func):
io_func = self.io_func.recreate(io_func) # type: ignore

return AwkwardInputLayer(
name=self.name,
Expand Down
11 changes: 10 additions & 1 deletion src/dask_awkward/lib/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,22 @@ def __init__(
success_callback: Callable[..., ak.Array],
failure_callback: Callable[..., ak.Array],
):
self.__reor_wrapped__ = fn
self.__rer_wrapped__ = fn
self.fn = fn
self.allowed_exceptions = allowed_exceptions
self.backend = backend
self.success_callback = success_callback
self.failure_callback = failure_callback

def recreate(self, fn):
return return_empty_on_raise(
fn,
self.allowed_exceptions,
self.backend,
self.success_callback,
self.failure_callback,
)

def __call__(self, *args, **kwargs):
try:
result = self.fn(*args, **kwargs)
Expand Down

0 comments on commit 25558bb

Please sign in to comment.