Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add __delitem__ to InferenceData #2295

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arviz/data/inference_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ def __delattr__(self, group: str) -> None:
self._groups_warmup.remove(group)
object.__delattr__(self, group)

def __delitem__(self, key: str) -> None:
"""Delete an item from the InferenceData object using del idata[key]."""
self.__delattr__(key)

@property
def _groups_all(self) -> List[str]:
return self._groups + self._groups_warmup
Expand Down
4 changes: 3 additions & 1 deletion arviz/tests/base_tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def test_sel_chain_prior(self):
with pytest.raises(KeyError):
idata.sel(inplace=False, chain_prior=True, chain=[0, 1, 3])

@pytest.mark.parametrize("use", ("del", "delattr"))
@pytest.mark.parametrize("use", ("del", "delattr", "delitem"))
def test_del(self, use):
# create inference data object
data = np.random.normal(size=(4, 500, 8))
Expand All @@ -523,6 +523,8 @@ def test_del(self, use):
# Use del method
if use == "del":
del idata.sample_stats
elif use == "delitem":
del idata["sample_stats"]
else:
delattr(idata, "sample_stats")

Expand Down
Loading