Skip to content

Commit fae2e4d

Browse files
test: add minimal test for array like objects (#2484)
1 parent 6b6c00a commit fae2e4d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

arviz/tests/base_tests/test_data.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,3 +1652,19 @@ def test_subset_samples(self):
16521652
post = extract(idata, num_samples=10)
16531653
assert post.sizes["sample"] == 10
16541654
assert post.attrs == idata.posterior.attrs
1655+
1656+
1657+
def test_convert_to_inference_data_with_array_like():
1658+
class ArrayLike:
1659+
def __init__(self, data):
1660+
self._data = np.asarray(data)
1661+
1662+
def __array__(self):
1663+
return self._data
1664+
1665+
array_like = ArrayLike(np.random.randn(4, 100))
1666+
idata = convert_to_inference_data(array_like, group="posterior")
1667+
1668+
assert hasattr(idata, "posterior")
1669+
assert "x" in idata.posterior.data_vars
1670+
assert idata.posterior["x"].shape == (4, 100)

0 commit comments

Comments
 (0)