-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve behaviour of DataTree accessor (#32)
* better default for datatree group handling * add test for datatree accessor group behaviour * lint
- Loading branch information
1 parent
d622d99
commit feb3084
Showing
8 changed files
with
80 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# pylint: disable=redefined-outer-name | ||
"""Test accessors. | ||
Accessor methods are very short, with the bulk of the computation/processing | ||
handled by private methods. Testing this shared infrastructural methods | ||
is the main goal of this module even if it does so via specific "regular" methods. | ||
""" | ||
|
||
import numpy as np | ||
import pytest | ||
from arviz_base import from_dict | ||
from datatree import DataTree | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def idata(): | ||
return from_dict( | ||
{ | ||
"posterior": { | ||
"a": np.random.normal(size=(4, 100)), | ||
"b": np.random.normal(size=(4, 100, 3)), | ||
}, | ||
"posterior_predictive": { | ||
"y": np.random.normal(size=(4, 100, 7)), | ||
}, | ||
} | ||
) | ||
|
||
|
||
def test_accessors_available(idata): | ||
assert hasattr(idata, "azstats") | ||
assert hasattr(idata.posterior.ds, "azstats") | ||
assert hasattr(idata.posterior["a"], "azstats") | ||
|
||
|
||
def test_datatree_single_group(idata): | ||
out = idata.azstats.ess(group="posterior") | ||
assert isinstance(out, DataTree) | ||
assert not out.children | ||
assert out.name == "posterior" | ||
|
||
|
||
def test_datatree_multiple_groups(idata): | ||
out = idata.azstats.ess(group=["posterior", "posterior_predictive"]) | ||
assert isinstance(out, DataTree) | ||
assert len(out.children) == 2 | ||
assert "posterior" in out.children | ||
assert "posterior_predictive" in out.children |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters