scikit-hep / awkward

Manipulate JSON-like data with NumPy-like idioms.
https://awkward-array.org
BSD 3-Clause "New" or "Revised" License
839 stars 89 forks source link

We need a custom exception type for all errors related to missing behaviors #1461

Open jpivarski opened 2 years ago

jpivarski commented 2 years ago

Description of new feature

Prompted by Dask needs (discussion with @martindurant and @douglasdavis), but probably a good idea overall. Losing behaviors is a common type of error and users should get more direct messaging about what (likely) happened.

agoose77 commented 1 year ago

Could you clarify the intention of this Jim? Is it to raise an error if an array has a nominal type but no class is found?

jpivarski commented 1 year ago

There's a set of errors that occur when we try to do things to a record (ufunc, reducer, ...) that would be possible if the record were overloaded with __record__ but aren't possible for bare records. Currently, we raise an error in these cases, which is correct, but it would be more convenient for downstream libraries if we had a custom exception subclass that is raised in all of these situations, or maybe a suite of them that all inherit from a custom mixin if one needs to be a subclass of ValueError, another a subclass of TypeError, etc.

Downstream libraries would then be able to

try:
    to_do_a_thing(awkward_array)
except TypeErrorMissingBehavior as err:
    err.add_note("You forgot to define a behavior!")
    raise

and be able to identify the actual problem more quickly.

agoose77 commented 1 year ago

OK, sounds like we need a public errors module that exports an exception hierarchy! Added to the todo.