scikit-hep / awkward-0.x

Manipulate arrays of complex data structures as easily as Numpy.
BSD 3-Clause "New" or "Revised" License
215 stars 39 forks source link

Actually use cache for newly-constructed VirtualArrays #231

Closed nsmith- closed 4 years ago

nsmith- commented 4 years ago

Also require cache to conform to MutableMapping interface, i.e. KeyError is the only exception that indicates trouble.

jpivarski commented 4 years ago

I had a question about one line, but this looks right. Give me a checkmark or thumbs up or something and I'll merge it.

nsmith- commented 4 years ago

My one other complaint is there's a lot of key in cache checks that may be optional if we trust the virtual array to have correct type before materialization. This isn't a huge deal, but there may be unnecessary overhead in the cases where the cache is backed by something slow.

jpivarski commented 4 years ago

You're right. In fact, if we trust try ... catch KeyError logic, then the cache doesn't have to have a __contains__ operation defined, and it can be more thread-safe because of the time that elapses between the key check and the extraction.

nsmith- commented 4 years ago

In python's Mapping abc, __contains__ is not abstract because of this very logic.