1

So a collection of records has been created using awkward.zip;

import awkward
pineapple = awkward.from_iter([3, 4])
tofu = awkward.from_iter([5, 6])
pizza = awkward.zip({"pineapple": pineapple, "tofu": tofu})

I'd like to remove one of the records/fields from the collection I'm working with. My first thought is to do del pizza['pineapple'], but that doesn't work. I could do;

pizza = awkward.zip({name: pizza[name] for name in awkward.fields(pizza)
                     if name != 'pineapple'})

But I'm wondering if there is something more efficient I could be doing. I'm not trying to delete the object pineapple, just remove the reference to it in the pizza.

Clumsy cat
  • 289
  • 1
  • 12

1 Answers1

1

There isn't an ak.Array.__del__, but that doesn't mean there couldn't be one. However, it would be implemented in much the same way you have above—it would build a new record with all fields except the one to remove. Amy operation that puts arrays together as records or spots arrays out of records are O(1) in the length of the arrays: they only change metadata, like reshaping a NumPy array. We generally only worry about performance for things that scale with the length of an array, as this is the parameter that can grow large (it's assumed that you'd have a lot more array entries than record fields).

You could also do it with a slice instead of an ak.zio:

pizza = pizza[[x for x in ak.fields(pizza) if x != "pineapple"]]

This would work regardless of how deep the records are within nested lists of lists. See nested projection.

Jim Pivarski
  • 5,568
  • 2
  • 35
  • 47