arviz-devs / arviz

Exploratory analysis of Bayesian models with Python
https://python.arviz.org
Apache License 2.0
1.56k stars 388 forks source link

Add a `__delitem__` method to InferenceData #2293

Closed Dekermanjian closed 6 months ago

Dekermanjian commented 7 months ago

I would like to be able to do something like this:

del idata["prior"]

At the moment I get the error:

TypeError: 'InferenceData' object does not support item deletion
Dekermanjian commented 7 months ago

Never mind, I found the way to do it. Just for anyone searching how to do this.

idata.__delattr__(group = <group name>)
OriolAbril commented 7 months ago

it looks like we have a __delattr__ method but not a __delitem__ one. You shouldn't call either directly though. To delete a group you should do:

del idata.prior

which will call __delattr__ under the hood. We need to add a __delitem__ method that calls the __delattr__ one. Do you want to send a PR for this?

Dekermanjian commented 6 months ago

@OriolAbril Hey, I am sorry for some reason I did not get alerted to your message until just now. Thank you for taking care of adding that in.