diff --git a/docs/developer_guide/example_docstrings.py b/docs/developer_guide/example_docstrings.py index 7d1306a3..b8e740c6 100644 --- a/docs/developer_guide/example_docstrings.py +++ b/docs/developer_guide/example_docstrings.py @@ -8,7 +8,7 @@ def example_function_args( param2: str | int, optional_param: list[str] | None = None, *args: float | str, - **kwargs: Dict[str, Any] + **kwargs: Dict[str, Any], ) -> tuple[bool, list[str]]: """Example function with PEP 484 type annotations and PEP 563 future annotations. diff --git a/medmodels/_medmodels.pyi b/medmodels/_medmodels.pyi index f8ebf367..543c4582 100644 --- a/medmodels/_medmodels.pyi +++ b/medmodels/_medmodels.pyi @@ -1,4 +1,3 @@ - from enum import Enum from typing import TYPE_CHECKING, Dict, List, Optional, Sequence, Union diff --git a/medmodels/medrecord/medrecord.py b/medmodels/medrecord/medrecord.py index 7a98c824..c7640516 100644 --- a/medmodels/medrecord/medrecord.py +++ b/medmodels/medrecord/medrecord.py @@ -776,9 +776,9 @@ def add_edges( edges ): return self.add_edges_pandas(edges, group) - if is_polars_edge_dataframe_input( + if is_polars_edge_dataframe_input(edges) or is_polars_edge_dataframe_input_list( edges - ) or is_polars_edge_dataframe_input_list(edges): + ): return self.add_edges_polars(edges, group) if is_edge_tuple(edges): edges = [edges] diff --git a/medmodels/medrecord/schema.py b/medmodels/medrecord/schema.py index bcc4e85d..5b0cd5fc 100644 --- a/medmodels/medrecord/schema.py +++ b/medmodels/medrecord/schema.py @@ -252,8 +252,12 @@ class GroupSchema: def __init__( self, *, - nodes: Optional[Dict[MedRecordAttribute, Union[DataType, Tuple[DataType, AttributeType]]]] = None, - edges: Optional[Dict[MedRecordAttribute, Union[DataType, Tuple[DataType, AttributeType]]]] = None, + nodes: Optional[ + Dict[MedRecordAttribute, Union[DataType, Tuple[DataType, AttributeType]]] + ] = None, + edges: Optional[ + Dict[MedRecordAttribute, Union[DataType, Tuple[DataType, AttributeType]]] + ] = None, strict: bool = False, ) -> None: """Initializes a new instance of GroupSchema. diff --git a/medmodels/medrecord/tests/test_datatype.py b/medmodels/medrecord/tests/test_datatype.py index 331519bb..6fd3c1c0 100644 --- a/medmodels/medrecord/tests/test_datatype.py +++ b/medmodels/medrecord/tests/test_datatype.py @@ -107,7 +107,10 @@ def test_union(self) -> None: assert str(union) == "Union(String, Union(Int, Bool))" - assert union.__repr__() == "DataType.Union(DataType.String, DataType.Union(DataType.Int, DataType.Bool))" + assert ( + union.__repr__() + == "DataType.Union(DataType.String, DataType.Union(DataType.Int, DataType.Bool))" + ) assert mr.Union(mr.String(), mr.Int()) == mr.Union(mr.String(), mr.Int()) assert mr.Union(mr.String(), mr.Int()) != mr.Union(mr.Int(), mr.String()) diff --git a/medmodels/medrecord/tests/test_indexers.py b/medmodels/medrecord/tests/test_indexers.py index b8879e82..49799a57 100644 --- a/medmodels/medrecord/tests/test_indexers.py +++ b/medmodels/medrecord/tests/test_indexers.py @@ -54,7 +54,10 @@ def test_node_getitem(self) -> None: with pytest.raises(ValueError): medrecord.node[0, ::1] - assert medrecord.node[[0, 1]] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}} + assert medrecord.node[[0, 1]] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + } with pytest.raises(IndexError): medrecord.node[[0, 50]] @@ -69,7 +72,10 @@ def test_node_getitem(self) -> None: with pytest.raises(KeyError): medrecord.node[[0, 1], "lorem"] - assert medrecord.node[[0, 1], ["foo", "bar"]] == {0: {"foo": "bar", "bar": "foo"}, 1: {"foo": "bar", "bar": "foo"}} + assert medrecord.node[[0, 1], ["foo", "bar"]] == { + 0: {"foo": "bar", "bar": "foo"}, + 1: {"foo": "bar", "bar": "foo"}, + } # Accessing a non-existing key should fail with pytest.raises(KeyError): @@ -79,7 +85,10 @@ def test_node_getitem(self) -> None: with pytest.raises(KeyError): medrecord.node[[0, 1], ["foo", "lorem"]] - assert medrecord.node[[0, 1], :] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}} + assert medrecord.node[[0, 1], :] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + } with pytest.raises(ValueError): medrecord.node[[0, 1], 1:] @@ -88,7 +97,10 @@ def test_node_getitem(self) -> None: with pytest.raises(ValueError): medrecord.node[[0, 1], ::1] - assert medrecord.node[node().index() >= 2] == {2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[node().index() >= 2] == { + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } # Empty query should not fail assert medrecord.node[node().index() > 3] == {} @@ -99,7 +111,10 @@ def test_node_getitem(self) -> None: with pytest.raises(KeyError): medrecord.node[node().index() >= 2, "test"] - assert medrecord.node[node().index() >= 2, ["foo", "bar"]] == {2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[node().index() >= 2, ["foo", "bar"]] == { + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } # Accessing a non-existing key should fail with pytest.raises(KeyError): @@ -109,7 +124,10 @@ def test_node_getitem(self) -> None: with pytest.raises(KeyError): medrecord.node[node().index() < 2, ["foo", "lorem"]] - assert medrecord.node[node().index() >= 2, :] == {2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[node().index() >= 2, :] == { + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.node[node().index() >= 2, 1:] @@ -118,7 +136,12 @@ def test_node_getitem(self) -> None: with pytest.raises(ValueError): medrecord.node[node().index() >= 2, ::1] - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.node[1:] @@ -140,7 +163,12 @@ def test_node_getitem(self) -> None: with pytest.raises(ValueError): medrecord.node[::1, "foo"] - assert medrecord.node[:, ["foo", "bar"]] == {0: {"foo": "bar", "bar": "foo"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:, ["foo", "bar"]] == { + 0: {"foo": "bar", "bar": "foo"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } # Accessing a non-existing key should fail with pytest.raises(KeyError): @@ -157,7 +185,12 @@ def test_node_getitem(self) -> None: with pytest.raises(ValueError): medrecord.node[::1, ["foo", "bar"]] - assert medrecord.node[:, :] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:, :] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.node[1:, :] @@ -177,7 +210,12 @@ def test_node_setitem(self) -> None: medrecord = create_medrecord() medrecord.node[0] = {"foo": "bar", "bar": "test"} - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "test"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "test"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Updating a non-existing node should fail @@ -186,15 +224,30 @@ def test_node_setitem(self) -> None: medrecord = create_medrecord() medrecord.node[0, "foo"] = "test" - assert medrecord.node[:] == {0: {"foo": "test", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "test", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[0, ["foo", "bar"]] = "test" - assert medrecord.node[:] == {0: {"foo": "test", "bar": "test", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "test", "bar": "test", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[0, :] = "test" - assert medrecord.node[:] == {0: {"foo": "test", "bar": "test", "lorem": "test"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "test", "bar": "test", "lorem": "test"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.node[0, 1:] = "test" @@ -205,15 +258,30 @@ def test_node_setitem(self) -> None: medrecord = create_medrecord() medrecord.node[[0, 1], "foo"] = "test" - assert medrecord.node[:] == {0: {"foo": "test", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "test", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "test", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "test", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[[0, 1], ["foo", "bar"]] = "test" - assert medrecord.node[:] == {0: {"foo": "test", "bar": "test", "lorem": "ipsum"}, 1: {"foo": "test", "bar": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "test", "bar": "test", "lorem": "ipsum"}, + 1: {"foo": "test", "bar": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[[0, 1], :] = "test" - assert medrecord.node[:] == {0: {"foo": "test", "bar": "test", "lorem": "test"}, 1: {"foo": "test", "bar": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "test", "bar": "test", "lorem": "test"}, + 1: {"foo": "test", "bar": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.node[[0, 1], 1:] = "test" @@ -224,7 +292,12 @@ def test_node_setitem(self) -> None: medrecord = create_medrecord() medrecord.node[node().index() >= 2] = {"foo": "bar", "bar": "test"} - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "test"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "test"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Empty query should not fail @@ -232,15 +305,30 @@ def test_node_setitem(self) -> None: medrecord = create_medrecord() medrecord.node[node().index() >= 2, "foo"] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "test", "bar": "foo"}, 3: {"foo": "test", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "test", "bar": "foo"}, + 3: {"foo": "test", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[node().index() >= 2, ["foo", "bar"]] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "test", "bar": "test"}, 3: {"foo": "test", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "test", "bar": "test"}, + 3: {"foo": "test", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[node().index() >= 2, :] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "test", "bar": "test"}, 3: {"foo": "test", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "test", "bar": "test"}, + 3: {"foo": "test", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.node[node().index() >= 2, 1:] = "test" @@ -251,7 +339,12 @@ def test_node_setitem(self) -> None: medrecord = create_medrecord() medrecord.node[:, "foo"] = "test" - assert medrecord.node[:] == {0: {"foo": "test", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "test", "bar": "foo"}, 2: {"foo": "test", "bar": "foo"}, 3: {"foo": "test", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "test", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "test", "bar": "foo"}, + 2: {"foo": "test", "bar": "foo"}, + 3: {"foo": "test", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.node[1:, "foo"] = "test" @@ -262,7 +355,12 @@ def test_node_setitem(self) -> None: medrecord = create_medrecord() medrecord.node[:, ["foo", "bar"]] = "test" - assert medrecord.node[:] == {0: {"foo": "test", "bar": "test", "lorem": "ipsum"}, 1: {"foo": "test", "bar": "test"}, 2: {"foo": "test", "bar": "test"}, 3: {"foo": "test", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "test", "bar": "test", "lorem": "ipsum"}, + 1: {"foo": "test", "bar": "test"}, + 2: {"foo": "test", "bar": "test"}, + 3: {"foo": "test", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.node[1:, ["foo", "bar"]] = "test" @@ -273,7 +371,12 @@ def test_node_setitem(self) -> None: medrecord = create_medrecord() medrecord.node[:, :] = "test" - assert medrecord.node[:] == {0: {"foo": "test", "bar": "test", "lorem": "test"}, 1: {"foo": "test", "bar": "test"}, 2: {"foo": "test", "bar": "test"}, 3: {"foo": "test", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "test", "bar": "test", "lorem": "test"}, + 1: {"foo": "test", "bar": "test"}, + 2: {"foo": "test", "bar": "test"}, + 3: {"foo": "test", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.node[1:, :] = "test" @@ -292,66 +395,159 @@ def test_node_setitem(self) -> None: medrecord = create_medrecord() medrecord.node[0, "test"] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[0, ["test", "test2"]] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test", "test2": "test"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: { + "foo": "bar", + "bar": "foo", + "lorem": "ipsum", + "test": "test", + "test2": "test", + }, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[[0, 1], "test"] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test"}, 1: {"foo": "bar", "bar": "foo", "test": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test"}, + 1: {"foo": "bar", "bar": "foo", "test": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[[0, 1], ["test", "test2"]] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test", "test2": "test"}, 1: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: { + "foo": "bar", + "bar": "foo", + "lorem": "ipsum", + "test": "test", + "test2": "test", + }, + 1: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[node().index() >= 2, "test"] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo", "test": "test"}, 3: {"foo": "bar", "bar": "test", "test": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo", "test": "test"}, + 3: {"foo": "bar", "bar": "test", "test": "test"}, + } medrecord = create_medrecord() medrecord.node[node().index() >= 2, ["test", "test2"]] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, 3: {"foo": "bar", "bar": "test", "test": "test", "test2": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, + 3: {"foo": "bar", "bar": "test", "test": "test", "test2": "test"}, + } medrecord = create_medrecord() medrecord.node[:, "test"] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test"}, 1: {"foo": "bar", "bar": "foo", "test": "test"}, 2: {"foo": "bar", "bar": "foo", "test": "test"}, 3: {"foo": "bar", "bar": "test", "test": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test"}, + 1: {"foo": "bar", "bar": "foo", "test": "test"}, + 2: {"foo": "bar", "bar": "foo", "test": "test"}, + 3: {"foo": "bar", "bar": "test", "test": "test"}, + } medrecord = create_medrecord() medrecord.node[:, ["test", "test2"]] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test", "test2": "test"}, 1: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, 2: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, 3: {"foo": "bar", "bar": "test", "test": "test", "test2": "test"}} + assert medrecord.node[:] == { + 0: { + "foo": "bar", + "bar": "foo", + "lorem": "ipsum", + "test": "test", + "test2": "test", + }, + 1: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, + 2: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, + 3: {"foo": "bar", "bar": "test", "test": "test", "test2": "test"}, + } # Adding and updating attributes medrecord = create_medrecord() medrecord.node[[0, 1], "lorem"] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "test"}, 1: {"foo": "bar", "bar": "foo", "lorem": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 1: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[[0, 1], ["lorem", "test"]] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 1: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 1: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[node().index() < 2, "lorem"] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "test"}, 1: {"foo": "bar", "bar": "foo", "lorem": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 1: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[node().index() < 2, ["lorem", "test"]] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 1: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 1: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.node[:, "lorem"] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "test"}, 1: {"foo": "bar", "bar": "foo", "lorem": "test"}, 2: {"foo": "bar", "bar": "foo", "lorem": "test"}, 3: {"foo": "bar", "bar": "test", "lorem": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 1: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 2: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 3: {"foo": "bar", "bar": "test", "lorem": "test"}, + } medrecord = create_medrecord() medrecord.node[:, ["lorem", "test"]] = "test" - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 1: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 2: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 3: {"foo": "bar", "bar": "test", "lorem": "test", "test": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 1: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 2: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 3: {"foo": "bar", "bar": "test", "lorem": "test", "test": "test"}, + } def test_node_delitem(self) -> None: medrecord = create_medrecord() del medrecord.node[0, "foo"] - assert medrecord.node[:] == {0: {"bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Removing from a non-existing node should fail @@ -365,7 +561,12 @@ def test_node_delitem(self) -> None: medrecord = create_medrecord() del medrecord.node[0, ["foo", "bar"]] - assert medrecord.node[:] == {0: {"lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Removing a non-existing key should fail @@ -374,7 +575,12 @@ def test_node_delitem(self) -> None: medrecord = create_medrecord() del medrecord.node[0, :] - assert medrecord.node[:] == {0: {}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): del medrecord.node[0, 1:] @@ -385,7 +591,12 @@ def test_node_delitem(self) -> None: medrecord = create_medrecord() del medrecord.node[[0, 1], "foo"] - assert medrecord.node[:] == {0: {"bar": "foo", "lorem": "ipsum"}, 1: {"bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"bar": "foo", "lorem": "ipsum"}, + 1: {"bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Removing from a non-existing node should fail @@ -399,7 +610,12 @@ def test_node_delitem(self) -> None: medrecord = create_medrecord() del medrecord.node[[0, 1], ["foo", "bar"]] - assert medrecord.node[:] == {0: {"lorem": "ipsum"}, 1: {}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"lorem": "ipsum"}, + 1: {}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Removing a non-existing key should fail @@ -413,7 +629,12 @@ def test_node_delitem(self) -> None: medrecord = create_medrecord() del medrecord.node[[0, 1], :] - assert medrecord.node[:] == {0: {}, 1: {}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {}, + 1: {}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): del medrecord.node[[0, 1], 1:] @@ -424,12 +645,22 @@ def test_node_delitem(self) -> None: medrecord = create_medrecord() del medrecord.node[node().index() >= 2, "foo"] - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"bar": "foo"}, 3: {"bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"bar": "foo"}, + 3: {"bar": "test"}, + } medrecord = create_medrecord() # Empty query should not fail del medrecord.node[node().index() > 3, "foo"] - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Removing a non-existing key should fail @@ -438,7 +669,12 @@ def test_node_delitem(self) -> None: medrecord = create_medrecord() del medrecord.node[node().index() >= 2, ["foo", "bar"]] - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {}, 3: {}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {}, + 3: {}, + } medrecord = create_medrecord() # Removing a non-existing key should fail @@ -452,7 +688,12 @@ def test_node_delitem(self) -> None: medrecord = create_medrecord() del medrecord.node[node().index() >= 2, :] - assert medrecord.node[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {}, 3: {}} + assert medrecord.node[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {}, + 3: {}, + } with pytest.raises(ValueError): del medrecord.node[node().index() >= 2, 1:] @@ -463,7 +704,12 @@ def test_node_delitem(self) -> None: medrecord = create_medrecord() del medrecord.node[:, "foo"] - assert medrecord.node[:] == {0: {"bar": "foo", "lorem": "ipsum"}, 1: {"bar": "foo"}, 2: {"bar": "foo"}, 3: {"bar": "test"}} + assert medrecord.node[:] == { + 0: {"bar": "foo", "lorem": "ipsum"}, + 1: {"bar": "foo"}, + 2: {"bar": "foo"}, + 3: {"bar": "test"}, + } medrecord = create_medrecord() # Removing a non-existing key should fail @@ -545,7 +791,10 @@ def test_edge_getitem(self) -> None: with pytest.raises(ValueError): medrecord.edge[0, ::1] - assert medrecord.edge[[0, 1]] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}} + assert medrecord.edge[[0, 1]] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + } with pytest.raises(IndexError): medrecord.edge[[0, 50]] @@ -560,7 +809,10 @@ def test_edge_getitem(self) -> None: with pytest.raises(KeyError): medrecord.edge[[0, 1], "lorem"] - assert medrecord.edge[[0, 1], ["foo", "bar"]] == {0: {"foo": "bar", "bar": "foo"}, 1: {"foo": "bar", "bar": "foo"}} + assert medrecord.edge[[0, 1], ["foo", "bar"]] == { + 0: {"foo": "bar", "bar": "foo"}, + 1: {"foo": "bar", "bar": "foo"}, + } # Accessing a non-existing key should fail with pytest.raises(KeyError): @@ -570,7 +822,10 @@ def test_edge_getitem(self) -> None: with pytest.raises(KeyError): medrecord.edge[[0, 1], ["foo", "lorem"]] - assert medrecord.edge[[0, 1], :] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}} + assert medrecord.edge[[0, 1], :] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + } with pytest.raises(ValueError): medrecord.edge[[0, 1], 1:] @@ -579,7 +834,10 @@ def test_edge_getitem(self) -> None: with pytest.raises(ValueError): medrecord.edge[[0, 1], ::1] - assert medrecord.edge[edge().index() >= 2] == {2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[edge().index() >= 2] == { + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } # Empty query should not fail assert medrecord.edge[edge().index() > 3] == {} @@ -590,7 +848,10 @@ def test_edge_getitem(self) -> None: with pytest.raises(KeyError): medrecord.edge[edge().index() >= 2, "test"] - assert medrecord.edge[edge().index() >= 2, ["foo", "bar"]] == {2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[edge().index() >= 2, ["foo", "bar"]] == { + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } # Accessing a non-existing key should fail with pytest.raises(KeyError): @@ -600,7 +861,10 @@ def test_edge_getitem(self) -> None: with pytest.raises(KeyError): medrecord.edge[edge().index() < 2, ["foo", "lorem"]] - assert medrecord.edge[edge().index() >= 2, :] == {2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[edge().index() >= 2, :] == { + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.edge[edge().index() >= 2, 1:] @@ -609,7 +873,12 @@ def test_edge_getitem(self) -> None: with pytest.raises(ValueError): medrecord.edge[edge().index() >= 2, ::1] - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.edge[1:] @@ -631,7 +900,12 @@ def test_edge_getitem(self) -> None: with pytest.raises(ValueError): medrecord.edge[::1, "foo"] - assert medrecord.edge[:, ["foo", "bar"]] == {0: {"foo": "bar", "bar": "foo"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:, ["foo", "bar"]] == { + 0: {"foo": "bar", "bar": "foo"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } # Accessing a non-existing key should fail with pytest.raises(KeyError): @@ -648,7 +922,12 @@ def test_edge_getitem(self) -> None: with pytest.raises(ValueError): medrecord.edge[::1, ["foo", "bar"]] - assert medrecord.edge[:, :] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:, :] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.edge[1:, :] @@ -668,7 +947,12 @@ def test_edge_setitem(self) -> None: medrecord = create_medrecord() medrecord.edge[0] = {"foo": "bar", "bar": "test"} - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "test"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "test"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Updating a non-existing edge should fail @@ -677,15 +961,30 @@ def test_edge_setitem(self) -> None: medrecord = create_medrecord() medrecord.edge[0, "foo"] = "test" - assert medrecord.edge[:] == {0: {"foo": "test", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "test", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[0, ["foo", "bar"]] = "test" - assert medrecord.edge[:] == {0: {"foo": "test", "bar": "test", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "test", "bar": "test", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[0, :] = "test" - assert medrecord.edge[:] == {0: {"foo": "test", "bar": "test", "lorem": "test"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "test", "bar": "test", "lorem": "test"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.edge[0, 1:] = "test" @@ -696,15 +995,30 @@ def test_edge_setitem(self) -> None: medrecord = create_medrecord() medrecord.edge[[0, 1], "foo"] = "test" - assert medrecord.edge[:] == {0: {"foo": "test", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "test", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "test", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "test", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[[0, 1], ["foo", "bar"]] = "test" - assert medrecord.edge[:] == {0: {"foo": "test", "bar": "test", "lorem": "ipsum"}, 1: {"foo": "test", "bar": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "test", "bar": "test", "lorem": "ipsum"}, + 1: {"foo": "test", "bar": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[[0, 1], :] = "test" - assert medrecord.edge[:] == {0: {"foo": "test", "bar": "test", "lorem": "test"}, 1: {"foo": "test", "bar": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "test", "bar": "test", "lorem": "test"}, + 1: {"foo": "test", "bar": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.edge[[0, 1], 1:] = "test" @@ -715,7 +1029,12 @@ def test_edge_setitem(self) -> None: medrecord = create_medrecord() medrecord.edge[edge().index() >= 2] = {"foo": "bar", "bar": "test"} - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "test"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "test"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Empty query should not fail @@ -723,15 +1042,30 @@ def test_edge_setitem(self) -> None: medrecord = create_medrecord() medrecord.edge[edge().index() >= 2, "foo"] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "test", "bar": "foo"}, 3: {"foo": "test", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "test", "bar": "foo"}, + 3: {"foo": "test", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[edge().index() >= 2, ["foo", "bar"]] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "test", "bar": "test"}, 3: {"foo": "test", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "test", "bar": "test"}, + 3: {"foo": "test", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[edge().index() >= 2, :] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "test", "bar": "test"}, 3: {"foo": "test", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "test", "bar": "test"}, + 3: {"foo": "test", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.edge[edge().index() >= 2, 1:] = "test" @@ -742,7 +1076,12 @@ def test_edge_setitem(self) -> None: medrecord = create_medrecord() medrecord.edge[:, "foo"] = "test" - assert medrecord.edge[:] == {0: {"foo": "test", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "test", "bar": "foo"}, 2: {"foo": "test", "bar": "foo"}, 3: {"foo": "test", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "test", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "test", "bar": "foo"}, + 2: {"foo": "test", "bar": "foo"}, + 3: {"foo": "test", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.edge[1:, "foo"] = "test" @@ -753,7 +1092,12 @@ def test_edge_setitem(self) -> None: medrecord = create_medrecord() medrecord.edge[:, ["foo", "bar"]] = "test" - assert medrecord.edge[:] == {0: {"foo": "test", "bar": "test", "lorem": "ipsum"}, 1: {"foo": "test", "bar": "test"}, 2: {"foo": "test", "bar": "test"}, 3: {"foo": "test", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "test", "bar": "test", "lorem": "ipsum"}, + 1: {"foo": "test", "bar": "test"}, + 2: {"foo": "test", "bar": "test"}, + 3: {"foo": "test", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.edge[1:, ["foo", "bar"]] = "test" @@ -764,7 +1108,12 @@ def test_edge_setitem(self) -> None: medrecord = create_medrecord() medrecord.edge[:, :] = "test" - assert medrecord.edge[:] == {0: {"foo": "test", "bar": "test", "lorem": "test"}, 1: {"foo": "test", "bar": "test"}, 2: {"foo": "test", "bar": "test"}, 3: {"foo": "test", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "test", "bar": "test", "lorem": "test"}, + 1: {"foo": "test", "bar": "test"}, + 2: {"foo": "test", "bar": "test"}, + 3: {"foo": "test", "bar": "test"}, + } with pytest.raises(ValueError): medrecord.edge[1:, :] = "test" @@ -783,66 +1132,159 @@ def test_edge_setitem(self) -> None: medrecord = create_medrecord() medrecord.edge[0, "test"] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[0, ["test", "test2"]] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test", "test2": "test"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: { + "foo": "bar", + "bar": "foo", + "lorem": "ipsum", + "test": "test", + "test2": "test", + }, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[[0, 1], "test"] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test"}, 1: {"foo": "bar", "bar": "foo", "test": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test"}, + 1: {"foo": "bar", "bar": "foo", "test": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[[0, 1], ["test", "test2"]] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test", "test2": "test"}, 1: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: { + "foo": "bar", + "bar": "foo", + "lorem": "ipsum", + "test": "test", + "test2": "test", + }, + 1: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[edge().index() >= 2, "test"] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo", "test": "test"}, 3: {"foo": "bar", "bar": "test", "test": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo", "test": "test"}, + 3: {"foo": "bar", "bar": "test", "test": "test"}, + } medrecord = create_medrecord() medrecord.edge[edge().index() >= 2, ["test", "test2"]] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, 3: {"foo": "bar", "bar": "test", "test": "test", "test2": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, + 3: {"foo": "bar", "bar": "test", "test": "test", "test2": "test"}, + } medrecord = create_medrecord() medrecord.edge[:, "test"] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test"}, 1: {"foo": "bar", "bar": "foo", "test": "test"}, 2: {"foo": "bar", "bar": "foo", "test": "test"}, 3: {"foo": "bar", "bar": "test", "test": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test"}, + 1: {"foo": "bar", "bar": "foo", "test": "test"}, + 2: {"foo": "bar", "bar": "foo", "test": "test"}, + 3: {"foo": "bar", "bar": "test", "test": "test"}, + } medrecord = create_medrecord() medrecord.edge[:, ["test", "test2"]] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum", "test": "test", "test2": "test"}, 1: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, 2: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, 3: {"foo": "bar", "bar": "test", "test": "test", "test2": "test"}} + assert medrecord.edge[:] == { + 0: { + "foo": "bar", + "bar": "foo", + "lorem": "ipsum", + "test": "test", + "test2": "test", + }, + 1: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, + 2: {"foo": "bar", "bar": "foo", "test": "test", "test2": "test"}, + 3: {"foo": "bar", "bar": "test", "test": "test", "test2": "test"}, + } # Adding and updating attributes medrecord = create_medrecord() medrecord.edge[[0, 1], "lorem"] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "test"}, 1: {"foo": "bar", "bar": "foo", "lorem": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 1: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[[0, 1], ["lorem", "test"]] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 1: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 1: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[edge().index() < 2, "lorem"] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "test"}, 1: {"foo": "bar", "bar": "foo", "lorem": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 1: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[edge().index() < 2, ["lorem", "test"]] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 1: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 1: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() medrecord.edge[:, "lorem"] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "test"}, 1: {"foo": "bar", "bar": "foo", "lorem": "test"}, 2: {"foo": "bar", "bar": "foo", "lorem": "test"}, 3: {"foo": "bar", "bar": "test", "lorem": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 1: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 2: {"foo": "bar", "bar": "foo", "lorem": "test"}, + 3: {"foo": "bar", "bar": "test", "lorem": "test"}, + } medrecord = create_medrecord() medrecord.edge[:, ["lorem", "test"]] = "test" - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 1: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 2: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, 3: {"foo": "bar", "bar": "test", "lorem": "test", "test": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 1: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 2: {"foo": "bar", "bar": "foo", "lorem": "test", "test": "test"}, + 3: {"foo": "bar", "bar": "test", "lorem": "test", "test": "test"}, + } def test_edge_delitem(self) -> None: medrecord = create_medrecord() del medrecord.edge[0, "foo"] - assert medrecord.edge[:] == {0: {"bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Removing from a non-existing edge should fail @@ -856,7 +1298,12 @@ def test_edge_delitem(self) -> None: medrecord = create_medrecord() del medrecord.edge[0, ["foo", "bar"]] - assert medrecord.edge[:] == {0: {"lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Removing a non-existing key should fail @@ -865,7 +1312,12 @@ def test_edge_delitem(self) -> None: medrecord = create_medrecord() del medrecord.edge[0, :] - assert medrecord.edge[:] == {0: {}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): del medrecord.edge[0, 1:] @@ -876,7 +1328,12 @@ def test_edge_delitem(self) -> None: medrecord = create_medrecord() del medrecord.edge[[0, 1], "foo"] - assert medrecord.edge[:] == {0: {"bar": "foo", "lorem": "ipsum"}, 1: {"bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"bar": "foo", "lorem": "ipsum"}, + 1: {"bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Removing from a non-existing edge should fail @@ -890,7 +1347,12 @@ def test_edge_delitem(self) -> None: medrecord = create_medrecord() del medrecord.edge[[0, 1], ["foo", "bar"]] - assert medrecord.edge[:] == {0: {"lorem": "ipsum"}, 1: {}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"lorem": "ipsum"}, + 1: {}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Removing a non-existing key should fail @@ -904,7 +1366,12 @@ def test_edge_delitem(self) -> None: medrecord = create_medrecord() del medrecord.edge[[0, 1], :] - assert medrecord.edge[:] == {0: {}, 1: {}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {}, + 1: {}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } with pytest.raises(ValueError): del medrecord.edge[[0, 1], 1:] @@ -915,12 +1382,22 @@ def test_edge_delitem(self) -> None: medrecord = create_medrecord() del medrecord.edge[edge().index() >= 2, "foo"] - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"bar": "foo"}, 3: {"bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"bar": "foo"}, + 3: {"bar": "test"}, + } medrecord = create_medrecord() # Empty query should not fail del medrecord.edge[edge().index() > 3, "foo"] - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {"foo": "bar", "bar": "foo"}, 3: {"foo": "bar", "bar": "test"}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {"foo": "bar", "bar": "foo"}, + 3: {"foo": "bar", "bar": "test"}, + } medrecord = create_medrecord() # Removing a non-existing key should fail @@ -929,7 +1406,12 @@ def test_edge_delitem(self) -> None: medrecord = create_medrecord() del medrecord.edge[edge().index() >= 2, ["foo", "bar"]] - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {}, 3: {}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {}, + 3: {}, + } medrecord = create_medrecord() # Removing a non-existing key should fail @@ -943,7 +1425,12 @@ def test_edge_delitem(self) -> None: medrecord = create_medrecord() del medrecord.edge[edge().index() >= 2, :] - assert medrecord.edge[:] == {0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, 1: {"foo": "bar", "bar": "foo"}, 2: {}, 3: {}} + assert medrecord.edge[:] == { + 0: {"foo": "bar", "bar": "foo", "lorem": "ipsum"}, + 1: {"foo": "bar", "bar": "foo"}, + 2: {}, + 3: {}, + } with pytest.raises(ValueError): del medrecord.edge[edge().index() >= 2, 1:] @@ -954,7 +1441,12 @@ def test_edge_delitem(self) -> None: medrecord = create_medrecord() del medrecord.edge[:, "foo"] - assert medrecord.edge[:] == {0: {"bar": "foo", "lorem": "ipsum"}, 1: {"bar": "foo"}, 2: {"bar": "foo"}, 3: {"bar": "test"}} + assert medrecord.edge[:] == { + 0: {"bar": "foo", "lorem": "ipsum"}, + 1: {"bar": "foo"}, + 2: {"bar": "foo"}, + 3: {"bar": "test"}, + } medrecord = create_medrecord() # Removing a non-existing key should fail diff --git a/medmodels/medrecord/tests/test_medrecord.py b/medmodels/medrecord/tests/test_medrecord.py index 20970043..314ca797 100644 --- a/medmodels/medrecord/tests/test_medrecord.py +++ b/medmodels/medrecord/tests/test_medrecord.py @@ -327,7 +327,10 @@ def test_group(self) -> None: assert medrecord.group("1") == {"nodes": ["0"], "edges": [0]} - assert medrecord.group(["0", "1"]) == {"0": {"nodes": [], "edges": []}, "1": {"nodes": ["0"], "edges": [0]}} + assert medrecord.group(["0", "1"]) == { + "0": {"nodes": [], "edges": []}, + "1": {"nodes": ["0"], "edges": [0]}, + } def test_invalid_group(self) -> None: medrecord = create_medrecord() @@ -351,11 +354,17 @@ def test_outgoing_edges(self) -> None: edges = medrecord.outgoing_edges(["0", "1"]) - assert {key: sorted(value) for key, value in edges.items()} == {"0": sorted([0, 3]), "1": [1, 2]} + assert {key: sorted(value) for key, value in edges.items()} == { + "0": sorted([0, 3]), + "1": [1, 2], + } edges = medrecord.outgoing_edges(node_select().index().is_in(["0", "1"])) - assert {key: sorted(value) for key, value in edges.items()} == {"0": sorted([0, 3]), "1": [1, 2]} + assert {key: sorted(value) for key, value in edges.items()} == { + "0": sorted([0, 3]), + "1": [1, 2], + } def test_invalid_outgoing_edges(self) -> None: medrecord = create_medrecord() @@ -1383,7 +1392,10 @@ def test_groups_of_node(self) -> None: assert medrecord.groups_of_node(["0", "1"]) == {"0": ["0"], "1": ["0"]} - assert medrecord.groups_of_node(node_select().index().is_in(["0", "1"])) == {"0": ["0"], "1": ["0"]} + assert medrecord.groups_of_node(node_select().index().is_in(["0", "1"])) == { + "0": ["0"], + "1": ["0"], + } def test_invalid_groups_of_node(self) -> None: medrecord = create_medrecord() @@ -1405,7 +1417,10 @@ def test_groups_of_edge(self) -> None: assert medrecord.groups_of_edge([0, 1]) == {0: ["0"], 1: ["0"]} - assert medrecord.groups_of_edge(edge_select().index().is_in([0, 1])) == {0: ["0"], 1: ["0"]} + assert medrecord.groups_of_edge(edge_select().index().is_in([0, 1])) == { + 0: ["0"], + 1: ["0"], + } def test_invalid_groups_of_edge(self) -> None: medrecord = create_medrecord() @@ -1480,11 +1495,17 @@ def test_neighbors(self) -> None: neighbors = medrecord.neighbors(["0", "1"]) - assert {key: sorted(value) for key, value in neighbors.items()} == {"0": sorted(["1", "3"]), "1": ["0", "2"]} + assert {key: sorted(value) for key, value in neighbors.items()} == { + "0": sorted(["1", "3"]), + "1": ["0", "2"], + } neighbors = medrecord.neighbors(node_select().index().is_in(["0", "1"])) - assert {key: sorted(value) for key, value in neighbors.items()} == {"0": sorted(["1", "3"]), "1": ["0", "2"]} + assert {key: sorted(value) for key, value in neighbors.items()} == { + "0": sorted(["1", "3"]), + "1": ["0", "2"], + } neighbors = medrecord.neighbors("0", directed=False) @@ -1492,13 +1513,19 @@ def test_neighbors(self) -> None: neighbors = medrecord.neighbors(["0", "1"], directed=False) - assert {key: sorted(value) for key, value in neighbors.items()} == {"0": sorted(["1", "3"]), "1": ["0", "2"]} + assert {key: sorted(value) for key, value in neighbors.items()} == { + "0": sorted(["1", "3"]), + "1": ["0", "2"], + } neighbors = medrecord.neighbors( node_select().index().is_in(["0", "1"]), directed=False ) - assert {key: sorted(value) for key, value in neighbors.items()} == {"0": sorted(["1", "3"]), "1": ["0", "2"]} + assert {key: sorted(value) for key, value in neighbors.items()} == { + "0": sorted(["1", "3"]), + "1": ["0", "2"], + } def test_invalid_neighbors(self) -> None: medrecord = create_medrecord() diff --git a/medmodels/medrecord/tests/test_querying.py b/medmodels/medrecord/tests/test_querying.py index d7b5b7e2..c0464efa 100644 --- a/medmodels/medrecord/tests/test_querying.py +++ b/medmodels/medrecord/tests/test_querying.py @@ -50,47 +50,75 @@ def test_select_nodes_node(self) -> None: assert medrecord.select_nodes(node().has_attribute("lorem")) == ["0"] # Node has outgoing edge with - assert medrecord.select_nodes(node().has_outgoing_edge_with(edge().index().equal(0))) == ["0"] + assert medrecord.select_nodes( + node().has_outgoing_edge_with(edge().index().equal(0)) + ) == ["0"] # Node has incoming edge with - assert medrecord.select_nodes(node().has_incoming_edge_with(edge().index().equal(0))) == ["1"] + assert medrecord.select_nodes( + node().has_incoming_edge_with(edge().index().equal(0)) + ) == ["1"] # Node has edge with - assert sorted(["0", "1"]) == sorted(medrecord.select_nodes(node().has_edge_with(edge().index().equal(0)))) + assert sorted(["0", "1"]) == sorted( + medrecord.select_nodes(node().has_edge_with(edge().index().equal(0))) + ) # Node has neighbor with - assert sorted(["0", "1"]) == sorted(medrecord.select_nodes(node().has_neighbor_with(node().index().equal("2")))) - assert sorted(["0"]) == sorted(medrecord.select_nodes(node().has_neighbor_with(node().index().equal("1"), directed=True))) + assert sorted(["0", "1"]) == sorted( + medrecord.select_nodes(node().has_neighbor_with(node().index().equal("2"))) + ) + assert sorted(["0"]) == sorted( + medrecord.select_nodes( + node().has_neighbor_with(node().index().equal("1"), directed=True) + ) + ) # Node has neighbor with - assert sorted(["0", "2"]) == sorted(medrecord.select_nodes(node().has_neighbor_with(node().index().equal("1"), directed=False))) + assert sorted(["0", "2"]) == sorted( + medrecord.select_nodes( + node().has_neighbor_with(node().index().equal("1"), directed=False) + ) + ) def test_select_nodes_node_index(self) -> None: medrecord = create_medrecord() # Index greater - assert sorted(["2", "3"]) == sorted(medrecord.select_nodes(node().index().greater("1"))) + assert sorted(["2", "3"]) == sorted( + medrecord.select_nodes(node().index().greater("1")) + ) # Index less - assert sorted(["0", "1"]) == sorted(medrecord.select_nodes(node().index().less("2"))) + assert sorted(["0", "1"]) == sorted( + medrecord.select_nodes(node().index().less("2")) + ) # Index greater or equal - assert sorted(["1", "2", "3"]) == sorted(medrecord.select_nodes(node().index().greater_or_equal("1"))) + assert sorted(["1", "2", "3"]) == sorted( + medrecord.select_nodes(node().index().greater_or_equal("1")) + ) # Index less or equal - assert sorted(["0", "1", "2"]) == sorted(medrecord.select_nodes(node().index().less_or_equal("2"))) + assert sorted(["0", "1", "2"]) == sorted( + medrecord.select_nodes(node().index().less_or_equal("2")) + ) # Index equal assert medrecord.select_nodes(node().index().equal("1")) == ["1"] # Index not equal - assert sorted(["0", "2", "3"]) == sorted(medrecord.select_nodes(node().index().not_equal("1"))) + assert sorted(["0", "2", "3"]) == sorted( + medrecord.select_nodes(node().index().not_equal("1")) + ) # Index in assert medrecord.select_nodes(node().index().is_in(["1"])) == ["1"] # Index not in - assert sorted(["0", "2", "3"]) == sorted(medrecord.select_nodes(node().index().not_in(["1"]))) + assert sorted(["0", "2", "3"]) == sorted( + medrecord.select_nodes(node().index().not_in(["1"])) + ) # Index starts with assert medrecord.select_nodes(node().index().starts_with("1")) == ["1"] @@ -113,11 +141,15 @@ def test_select_nodes_node_attribute(self) -> None: assert medrecord.select_nodes(node().attribute("lorem") < "ipsum") == [] # Attribute greater or equal - assert medrecord.select_nodes(node().attribute("lorem").greater_or_equal("ipsum")) == ["0"] + assert medrecord.select_nodes( + node().attribute("lorem").greater_or_equal("ipsum") + ) == ["0"] assert medrecord.select_nodes(node().attribute("lorem") >= "ipsum") == ["0"] # Attribute less or equal - assert medrecord.select_nodes(node().attribute("lorem").less_or_equal("ipsum")) == ["0"] + assert medrecord.select_nodes( + node().attribute("lorem").less_or_equal("ipsum") + ) == ["0"] assert medrecord.select_nodes(node().attribute("lorem") <= "ipsum") == ["0"] # Attribute equal @@ -125,120 +157,332 @@ def test_select_nodes_node_attribute(self) -> None: assert medrecord.select_nodes(node().attribute("lorem") == "ipsum") == ["0"] # Attribute not equal - assert medrecord.select_nodes(node().attribute("lorem").not_equal("ipsum")) == [] + assert ( + medrecord.select_nodes(node().attribute("lorem").not_equal("ipsum")) == [] + ) assert medrecord.select_nodes(node().attribute("lorem") != "ipsum") == [] # Attribute in - assert medrecord.select_nodes(node().attribute("lorem").is_in(["ipsum"])) == ["0"] + assert medrecord.select_nodes(node().attribute("lorem").is_in(["ipsum"])) == [ + "0" + ] # Attribute not in assert medrecord.select_nodes(node().attribute("lorem").not_in(["ipsum"])) == [] # Attribute starts with - assert medrecord.select_nodes(node().attribute("lorem").starts_with("ip")) == ["0"] + assert medrecord.select_nodes(node().attribute("lorem").starts_with("ip")) == [ + "0" + ] # Attribute ends with - assert medrecord.select_nodes(node().attribute("lorem").ends_with("um")) == ["0"] + assert medrecord.select_nodes(node().attribute("lorem").ends_with("um")) == [ + "0" + ] # Attribute contains assert medrecord.select_nodes(node().attribute("lorem").contains("su")) == ["0"] # Attribute compare to attribute - assert medrecord.select_nodes(node().attribute("lorem").equal(node().attribute("lorem"))) == ["0"] - assert medrecord.select_nodes(node().attribute("lorem").not_equal(node().attribute("lorem"))) == [] + assert medrecord.select_nodes( + node().attribute("lorem").equal(node().attribute("lorem")) + ) == ["0"] + assert ( + medrecord.select_nodes( + node().attribute("lorem").not_equal(node().attribute("lorem")) + ) + == [] + ) # Attribute compare to attribute add - assert medrecord.select_nodes(node().attribute("lorem").equal(node().attribute("lorem").add("10"))) == [] - assert medrecord.select_nodes(node().attribute("lorem") == node().attribute("lorem") + "10") == [] - assert medrecord.select_nodes(node().attribute("lorem").not_equal(node().attribute("lorem").add("10"))) == ["0"] - assert medrecord.select_nodes(node().attribute("lorem") != node().attribute("lorem") + "10") == ["0"] + assert ( + medrecord.select_nodes( + node().attribute("lorem").equal(node().attribute("lorem").add("10")) + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem") == node().attribute("lorem") + "10" + ) + == [] + ) + assert medrecord.select_nodes( + node().attribute("lorem").not_equal(node().attribute("lorem").add("10")) + ) == ["0"] + assert medrecord.select_nodes( + node().attribute("lorem") != node().attribute("lorem") + "10" + ) == ["0"] # Attribute compare to attribute sub # Returns nothing because can't sub a string - assert medrecord.select_nodes(node().attribute("lorem").equal(node().attribute("lorem").sub("10"))) == [] - assert medrecord.select_nodes(node().attribute("lorem") == node().attribute("lorem") + "10") == [] - assert medrecord.select_nodes(node().attribute("lorem").not_equal(node().attribute("lorem").sub("10"))) == [] - assert medrecord.select_nodes(node().attribute("lorem") != node().attribute("lorem") - "10") == [] + assert ( + medrecord.select_nodes( + node().attribute("lorem").equal(node().attribute("lorem").sub("10")) + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem") == node().attribute("lorem") + "10" + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem").not_equal(node().attribute("lorem").sub("10")) + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem") != node().attribute("lorem") - "10" + ) + == [] + ) # Attribute compare to attribute sub - assert medrecord.select_nodes(node().attribute("integer").equal(node().attribute("integer").sub(10))) == [] - assert medrecord.select_nodes(node().attribute("integer").not_equal(node().attribute("integer").sub(10))) == ["0"] + assert ( + medrecord.select_nodes( + node().attribute("integer").equal(node().attribute("integer").sub(10)) + ) + == [] + ) + assert medrecord.select_nodes( + node().attribute("integer").not_equal(node().attribute("integer").sub(10)) + ) == ["0"] # Attribute compare to attribute mul - assert medrecord.select_nodes(node().attribute("lorem").equal(node().attribute("lorem").mul(2))) == [] - assert medrecord.select_nodes(node().attribute("lorem") == node().attribute("lorem") * 2) == [] - assert medrecord.select_nodes(node().attribute("lorem").not_equal(node().attribute("lorem").mul(2))) == ["0"] - assert medrecord.select_nodes(node().attribute("lorem") != node().attribute("lorem") * 2) == ["0"] + assert ( + medrecord.select_nodes( + node().attribute("lorem").equal(node().attribute("lorem").mul(2)) + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem") == node().attribute("lorem") * 2 + ) + == [] + ) + assert medrecord.select_nodes( + node().attribute("lorem").not_equal(node().attribute("lorem").mul(2)) + ) == ["0"] + assert medrecord.select_nodes( + node().attribute("lorem") != node().attribute("lorem") * 2 + ) == ["0"] # Attribute compare to attribute div # Returns nothing because can't div a string - assert medrecord.select_nodes(node().attribute("lorem").equal(node().attribute("lorem").div("10"))) == [] - assert medrecord.select_nodes(node().attribute("lorem") == node().attribute("lorem") / "10") == [] - assert medrecord.select_nodes(node().attribute("lorem").not_equal(node().attribute("lorem").div("10"))) == [] - assert medrecord.select_nodes(node().attribute("lorem") != node().attribute("lorem") / "10") == [] + assert ( + medrecord.select_nodes( + node().attribute("lorem").equal(node().attribute("lorem").div("10")) + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem") == node().attribute("lorem") / "10" + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem").not_equal(node().attribute("lorem").div("10")) + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem") != node().attribute("lorem") / "10" + ) + == [] + ) # Attribute compare to attribute div - assert medrecord.select_nodes(node().attribute("integer").equal(node().attribute("integer").div(2))) == [] - assert medrecord.select_nodes(node().attribute("integer").not_equal(node().attribute("integer").div(2))) == ["0"] + assert ( + medrecord.select_nodes( + node().attribute("integer").equal(node().attribute("integer").div(2)) + ) + == [] + ) + assert medrecord.select_nodes( + node().attribute("integer").not_equal(node().attribute("integer").div(2)) + ) == ["0"] # Attribute compare to attribute pow # Returns nothing because can't pow a string - assert medrecord.select_nodes(node().attribute("lorem").equal(node().attribute("lorem").pow("10"))) == [] - assert medrecord.select_nodes(node().attribute("lorem") == node().attribute("lorem") ** "10") == [] - assert medrecord.select_nodes(node().attribute("lorem").not_equal(node().attribute("lorem").pow("10"))) == [] - assert medrecord.select_nodes(node().attribute("lorem") != node().attribute("lorem") ** "10") == [] + assert ( + medrecord.select_nodes( + node().attribute("lorem").equal(node().attribute("lorem").pow("10")) + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem") == node().attribute("lorem") ** "10" + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem").not_equal(node().attribute("lorem").pow("10")) + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem") != node().attribute("lorem") ** "10" + ) + == [] + ) # Attribute compare to attribute pow - assert medrecord.select_nodes(node().attribute("integer").equal(node().attribute("integer").pow(2))) == ["0"] - assert medrecord.select_nodes(node().attribute("integer").not_equal(node().attribute("integer").pow(2))) == [] + assert medrecord.select_nodes( + node().attribute("integer").equal(node().attribute("integer").pow(2)) + ) == ["0"] + assert ( + medrecord.select_nodes( + node() + .attribute("integer") + .not_equal(node().attribute("integer").pow(2)) + ) + == [] + ) # Attribute compare to attribute mod # Returns nothing because can't mod a string - assert medrecord.select_nodes(node().attribute("lorem").equal(node().attribute("lorem").mod("10"))) == [] - assert medrecord.select_nodes(node().attribute("lorem") == node().attribute("lorem") % "10") == [] - assert medrecord.select_nodes(node().attribute("lorem").not_equal(node().attribute("lorem").mod("10"))) == [] - assert medrecord.select_nodes(node().attribute("lorem") != node().attribute("lorem") % "10") == [] + assert ( + medrecord.select_nodes( + node().attribute("lorem").equal(node().attribute("lorem").mod("10")) + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem") == node().attribute("lorem") % "10" + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem").not_equal(node().attribute("lorem").mod("10")) + ) + == [] + ) + assert ( + medrecord.select_nodes( + node().attribute("lorem") != node().attribute("lorem") % "10" + ) + == [] + ) # Attribute compare to attribute mod - assert medrecord.select_nodes(node().attribute("integer").equal(node().attribute("integer").mod(2))) == ["0"] - assert medrecord.select_nodes(node().attribute("integer").not_equal(node().attribute("integer").mod(2))) == [] + assert medrecord.select_nodes( + node().attribute("integer").equal(node().attribute("integer").mod(2)) + ) == ["0"] + assert ( + medrecord.select_nodes( + node() + .attribute("integer") + .not_equal(node().attribute("integer").mod(2)) + ) + == [] + ) # Attribute compare to attribute round - assert medrecord.select_nodes(node().attribute("lorem").equal(node().attribute("lorem").round())) == ["0"] - assert medrecord.select_nodes(node().attribute("lorem").not_equal(node().attribute("lorem").round())) == [] - assert medrecord.select_nodes(node().attribute("integer").equal(node().attribute("float").round())) == ["0"] - assert medrecord.select_nodes(node().attribute("float").not_equal(node().attribute("float").round())) == ["0"] + assert medrecord.select_nodes( + node().attribute("lorem").equal(node().attribute("lorem").round()) + ) == ["0"] + assert ( + medrecord.select_nodes( + node().attribute("lorem").not_equal(node().attribute("lorem").round()) + ) + == [] + ) + assert medrecord.select_nodes( + node().attribute("integer").equal(node().attribute("float").round()) + ) == ["0"] + assert medrecord.select_nodes( + node().attribute("float").not_equal(node().attribute("float").round()) + ) == ["0"] # Attribute compare to attribute round - assert medrecord.select_nodes(node().attribute("integer").equal(node().attribute("float").ceil())) == ["0"] - assert medrecord.select_nodes(node().attribute("float").not_equal(node().attribute("float").ceil())) == ["0"] + assert medrecord.select_nodes( + node().attribute("integer").equal(node().attribute("float").ceil()) + ) == ["0"] + assert medrecord.select_nodes( + node().attribute("float").not_equal(node().attribute("float").ceil()) + ) == ["0"] # Attribute compare to attribute floor - assert medrecord.select_nodes(node().attribute("integer").equal(node().attribute("float").floor())) == [] - assert medrecord.select_nodes(node().attribute("float").not_equal(node().attribute("float").floor())) == ["0"] + assert ( + medrecord.select_nodes( + node().attribute("integer").equal(node().attribute("float").floor()) + ) + == [] + ) + assert medrecord.select_nodes( + node().attribute("float").not_equal(node().attribute("float").floor()) + ) == ["0"] # Attribute compare to attribute abs - assert medrecord.select_nodes(node().attribute("integer").equal(node().attribute("integer").abs())) == ["0"] - assert medrecord.select_nodes(node().attribute("integer").not_equal(node().attribute("integer").abs())) == [] + assert medrecord.select_nodes( + node().attribute("integer").equal(node().attribute("integer").abs()) + ) == ["0"] + assert ( + medrecord.select_nodes( + node().attribute("integer").not_equal(node().attribute("integer").abs()) + ) + == [] + ) # Attribute compare to attribute sqrt - assert medrecord.select_nodes(node().attribute("integer").equal(node().attribute("integer").sqrt())) == ["0"] - assert medrecord.select_nodes(node().attribute("integer").not_equal(node().attribute("integer").sqrt())) == [] + assert medrecord.select_nodes( + node().attribute("integer").equal(node().attribute("integer").sqrt()) + ) == ["0"] + assert ( + medrecord.select_nodes( + node() + .attribute("integer") + .not_equal(node().attribute("integer").sqrt()) + ) + == [] + ) # Attribute compare to attribute trim - assert medrecord.select_nodes(node().attribute("lorem").equal(node().attribute("dolor").trim())) == ["0"] + assert medrecord.select_nodes( + node().attribute("lorem").equal(node().attribute("dolor").trim()) + ) == ["0"] # Attribute compare to attribute trim_start - assert medrecord.select_nodes(node().attribute("lorem").equal(node().attribute("dolor").trim_start())) == [] + assert ( + medrecord.select_nodes( + node().attribute("lorem").equal(node().attribute("dolor").trim_start()) + ) + == [] + ) # Attribute compare to attribute trim_end - assert medrecord.select_nodes(node().attribute("lorem").equal(node().attribute("dolor").trim_end())) == [] + assert ( + medrecord.select_nodes( + node().attribute("lorem").equal(node().attribute("dolor").trim_end()) + ) + == [] + ) # Attribute compare to attribute lowercase - assert medrecord.select_nodes(node().attribute("lorem").equal(node().attribute("test").lowercase())) == ["0"] + assert medrecord.select_nodes( + node().attribute("lorem").equal(node().attribute("test").lowercase()) + ) == ["0"] # Attribute compare to attribute uppercase - assert medrecord.select_nodes(node().attribute("lorem").equal(node().attribute("test").uppercase())) == [] + assert ( + medrecord.select_nodes( + node().attribute("lorem").equal(node().attribute("test").uppercase()) + ) + == [] + ) def test_select_edges_edge(self) -> None: medrecord = create_medrecord() @@ -246,10 +490,14 @@ def test_select_edges_edge(self) -> None: medrecord.add_group("test", edges=[0]) # Edge connected to target - assert sorted([1, 2, 3]) == sorted(medrecord.select_edges(edge().connected_target("2"))) + assert sorted([1, 2, 3]) == sorted( + medrecord.select_edges(edge().connected_target("2")) + ) # Edge connected to source - assert sorted([0, 2, 3]) == sorted(medrecord.select_edges(edge().connected_source("0"))) + assert sorted([0, 2, 3]) == sorted( + medrecord.select_edges(edge().connected_source("0")) + ) # Edge connected assert sorted([0, 1]) == sorted(medrecord.select_edges(edge().connected("1"))) @@ -261,46 +509,72 @@ def test_select_edges_edge(self) -> None: assert medrecord.select_edges(edge().has_attribute("sed")) == [0] # Edge connected to target with - assert medrecord.select_edges(edge().connected_target_with(node().index().equal("1"))) == [0] + assert medrecord.select_edges( + edge().connected_target_with(node().index().equal("1")) + ) == [0] # Edge connected to source with - assert sorted([0, 2, 3]) == sorted(medrecord.select_edges(edge().connected_source_with(node().index().equal("0")))) + assert sorted([0, 2, 3]) == sorted( + medrecord.select_edges( + edge().connected_source_with(node().index().equal("0")) + ) + ) # Edge connected with - assert sorted([0, 1]) == sorted(medrecord.select_edges(edge().connected_with(node().index().equal("1")))) + assert sorted([0, 1]) == sorted( + medrecord.select_edges(edge().connected_with(node().index().equal("1"))) + ) # Edge has parallel edges with - assert sorted([2, 3]) == sorted(medrecord.select_edges(edge().has_parallel_edges_with(edge().has_attribute("test")))) + assert sorted([2, 3]) == sorted( + medrecord.select_edges( + edge().has_parallel_edges_with(edge().has_attribute("test")) + ) + ) # Edge has parallel edges with self comparison - assert medrecord.select_edges(edge().has_parallel_edges_with_self_comparison(edge().attribute("test").equal(edge().attribute("test").sub(1)))) == [2] + assert medrecord.select_edges( + edge().has_parallel_edges_with_self_comparison( + edge().attribute("test").equal(edge().attribute("test").sub(1)) + ) + ) == [2] def test_select_edges_edge_index(self) -> None: medrecord = create_medrecord() # Index greater - assert sorted([2, 3]) == sorted(medrecord.select_edges(edge().index().greater(1))) + assert sorted([2, 3]) == sorted( + medrecord.select_edges(edge().index().greater(1)) + ) # Index less assert medrecord.select_edges(edge().index().less(1)) == [0] # Index greater or equal - assert sorted([1, 2, 3]) == sorted(medrecord.select_edges(edge().index().greater_or_equal(1))) + assert sorted([1, 2, 3]) == sorted( + medrecord.select_edges(edge().index().greater_or_equal(1)) + ) # Index less or equal - assert sorted([0, 1]) == sorted(medrecord.select_edges(edge().index().less_or_equal(1))) + assert sorted([0, 1]) == sorted( + medrecord.select_edges(edge().index().less_or_equal(1)) + ) # Index equal assert medrecord.select_edges(edge().index().equal(1)) == [1] # Index not equal - assert sorted([0, 2, 3]) == sorted(medrecord.select_edges(edge().index().not_equal(1))) + assert sorted([0, 2, 3]) == sorted( + medrecord.select_edges(edge().index().not_equal(1)) + ) # Index in assert medrecord.select_edges(edge().index().is_in([1])) == [1] # Index not in - assert sorted([0, 2, 3]) == sorted(medrecord.select_edges(edge().index().not_in([1]))) + assert sorted([0, 2, 3]) == sorted( + medrecord.select_edges(edge().index().not_in([1])) + ) def test_select_edges_edges_attribute(self) -> None: medrecord = create_medrecord() @@ -312,10 +586,14 @@ def test_select_edges_edges_attribute(self) -> None: assert medrecord.select_edges(edge().attribute("sed").less("do")) == [] # Attribute greater or equal - assert medrecord.select_edges(edge().attribute("sed").greater_or_equal("do")) == [0] + assert medrecord.select_edges( + edge().attribute("sed").greater_or_equal("do") + ) == [0] # Attribute less or equal - assert medrecord.select_edges(edge().attribute("sed").less_or_equal("do")) == [0] + assert medrecord.select_edges(edge().attribute("sed").less_or_equal("do")) == [ + 0 + ] # Attribute equal assert medrecord.select_edges(edge().attribute("sed").equal("do")) == [0] @@ -339,98 +617,302 @@ def test_select_edges_edges_attribute(self) -> None: assert medrecord.select_edges(edge().attribute("sed").contains("d")) == [0] # Attribute compare to attribute - assert medrecord.select_edges(edge().attribute("sed").equal(edge().attribute("sed"))) == [0] - assert medrecord.select_edges(edge().attribute("sed").not_equal(edge().attribute("sed"))) == [] + assert medrecord.select_edges( + edge().attribute("sed").equal(edge().attribute("sed")) + ) == [0] + assert ( + medrecord.select_edges( + edge().attribute("sed").not_equal(edge().attribute("sed")) + ) + == [] + ) # Attribute compare to attribute add - assert medrecord.select_edges(edge().attribute("sed").equal(edge().attribute("sed").add("10"))) == [] - assert medrecord.select_edges(edge().attribute("sed") == edge().attribute("sed") + "10") == [] - assert medrecord.select_edges(edge().attribute("sed").not_equal(edge().attribute("sed").add("10"))) == [0] - assert medrecord.select_edges(edge().attribute("sed") != edge().attribute("sed") + "10") == [0] + assert ( + medrecord.select_edges( + edge().attribute("sed").equal(edge().attribute("sed").add("10")) + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("sed") == edge().attribute("sed") + "10" + ) + == [] + ) + assert medrecord.select_edges( + edge().attribute("sed").not_equal(edge().attribute("sed").add("10")) + ) == [0] + assert medrecord.select_edges( + edge().attribute("sed") != edge().attribute("sed") + "10" + ) == [0] # Attribute compare to attribute sub # Returns nothing because can't sub a string - assert medrecord.select_edges(edge().attribute("sed").equal(edge().attribute("sed").sub("10"))) == [] - assert medrecord.select_edges(edge().attribute("sed") == edge().attribute("sed") - "10") == [] - assert medrecord.select_edges(edge().attribute("sed").not_equal(edge().attribute("sed").sub("10"))) == [] - assert medrecord.select_edges(edge().attribute("sed") != edge().attribute("sed") - "10") == [] + assert ( + medrecord.select_edges( + edge().attribute("sed").equal(edge().attribute("sed").sub("10")) + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("sed") == edge().attribute("sed") - "10" + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("sed").not_equal(edge().attribute("sed").sub("10")) + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("sed") != edge().attribute("sed") - "10" + ) + == [] + ) # Attribute compare to attribute sub - assert medrecord.select_edges(edge().attribute("integer").equal(edge().attribute("integer").sub(10))) == [] - assert medrecord.select_edges(edge().attribute("integer").not_equal(edge().attribute("integer").sub(10))) == [2] + assert ( + medrecord.select_edges( + edge().attribute("integer").equal(edge().attribute("integer").sub(10)) + ) + == [] + ) + assert medrecord.select_edges( + edge().attribute("integer").not_equal(edge().attribute("integer").sub(10)) + ) == [2] # Attribute compare to attribute mul - assert medrecord.select_edges(edge().attribute("sed").equal(edge().attribute("sed").mul(2))) == [] - assert medrecord.select_edges(edge().attribute("sed") == edge().attribute("sed") * 2) == [] - assert medrecord.select_edges(edge().attribute("sed").not_equal(edge().attribute("sed").mul(2))) == [0] - assert medrecord.select_edges(edge().attribute("sed") != edge().attribute("sed") * 2) == [0] + assert ( + medrecord.select_edges( + edge().attribute("sed").equal(edge().attribute("sed").mul(2)) + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("sed") == edge().attribute("sed") * 2 + ) + == [] + ) + assert medrecord.select_edges( + edge().attribute("sed").not_equal(edge().attribute("sed").mul(2)) + ) == [0] + assert medrecord.select_edges( + edge().attribute("sed") != edge().attribute("sed") * 2 + ) == [0] # Attribute compare to attribute div # Returns nothing because can't div a string - assert medrecord.select_edges(edge().attribute("sed").equal(edge().attribute("sed").div("10"))) == [] - assert medrecord.select_edges(edge().attribute("sed") == edge().attribute("sed") / "10") == [] - assert medrecord.select_edges(edge().attribute("sed").not_equal(edge().attribute("sed").div("10"))) == [] - assert medrecord.select_edges(edge().attribute("sed") != edge().attribute("sed") / "10") == [] + assert ( + medrecord.select_edges( + edge().attribute("sed").equal(edge().attribute("sed").div("10")) + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("sed") == edge().attribute("sed") / "10" + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("sed").not_equal(edge().attribute("sed").div("10")) + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("sed") != edge().attribute("sed") / "10" + ) + == [] + ) # Attribute compare to attribute div - assert medrecord.select_edges(edge().attribute("integer").equal(edge().attribute("integer").div(2))) == [] - assert medrecord.select_edges(edge().attribute("integer").not_equal(edge().attribute("integer").div(2))) == [2] + assert ( + medrecord.select_edges( + edge().attribute("integer").equal(edge().attribute("integer").div(2)) + ) + == [] + ) + assert medrecord.select_edges( + edge().attribute("integer").not_equal(edge().attribute("integer").div(2)) + ) == [2] # Attribute compare to attribute pow # Returns nothing because can't pow a string - assert medrecord.select_edges(edge().attribute("lorem").equal(edge().attribute("lorem").pow("10"))) == [] - assert medrecord.select_edges(edge().attribute("lorem") == edge().attribute("lorem") ** "10") == [] - assert medrecord.select_edges(edge().attribute("lorem").not_equal(edge().attribute("lorem").pow("10"))) == [] - assert medrecord.select_edges(edge().attribute("lorem") != edge().attribute("lorem") ** "10") == [] + assert ( + medrecord.select_edges( + edge().attribute("lorem").equal(edge().attribute("lorem").pow("10")) + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("lorem") == edge().attribute("lorem") ** "10" + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("lorem").not_equal(edge().attribute("lorem").pow("10")) + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("lorem") != edge().attribute("lorem") ** "10" + ) + == [] + ) # Attribute compare to attribute pow - assert medrecord.select_edges(edge().attribute("integer").equal(edge().attribute("integer").pow(2))) == [2] - assert medrecord.select_edges(edge().attribute("integer").not_equal(edge().attribute("integer").pow(2))) == [] + assert medrecord.select_edges( + edge().attribute("integer").equal(edge().attribute("integer").pow(2)) + ) == [2] + assert ( + medrecord.select_edges( + edge() + .attribute("integer") + .not_equal(edge().attribute("integer").pow(2)) + ) + == [] + ) # Attribute compare to attribute mod # Returns nothing because can't mod a string - assert medrecord.select_edges(edge().attribute("lorem").equal(edge().attribute("lorem").mod("10"))) == [] - assert medrecord.select_edges(edge().attribute("lorem") == edge().attribute("lorem") % "10") == [] - assert medrecord.select_edges(edge().attribute("lorem").not_equal(edge().attribute("lorem").mod("10"))) == [] - assert medrecord.select_edges(edge().attribute("lorem") != edge().attribute("lorem") % "10") == [] + assert ( + medrecord.select_edges( + edge().attribute("lorem").equal(edge().attribute("lorem").mod("10")) + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("lorem") == edge().attribute("lorem") % "10" + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("lorem").not_equal(edge().attribute("lorem").mod("10")) + ) + == [] + ) + assert ( + medrecord.select_edges( + edge().attribute("lorem") != edge().attribute("lorem") % "10" + ) + == [] + ) # Attribute compare to attribute mod - assert medrecord.select_edges(edge().attribute("integer").equal(edge().attribute("integer").mod(2))) == [2] - assert medrecord.select_edges(edge().attribute("integer").not_equal(edge().attribute("integer").mod(2))) == [] + assert medrecord.select_edges( + edge().attribute("integer").equal(edge().attribute("integer").mod(2)) + ) == [2] + assert ( + medrecord.select_edges( + edge() + .attribute("integer") + .not_equal(edge().attribute("integer").mod(2)) + ) + == [] + ) # Attribute compare to attribute round - assert medrecord.select_edges(edge().attribute("sed").equal(edge().attribute("sed").round())) == [0] - assert medrecord.select_edges(edge().attribute("sed").not_equal(edge().attribute("sed").round())) == [] - assert medrecord.select_edges(edge().attribute("integer").equal(edge().attribute("float").round())) == [2] - assert medrecord.select_edges(edge().attribute("float").not_equal(edge().attribute("float").round())) == [2] + assert medrecord.select_edges( + edge().attribute("sed").equal(edge().attribute("sed").round()) + ) == [0] + assert ( + medrecord.select_edges( + edge().attribute("sed").not_equal(edge().attribute("sed").round()) + ) + == [] + ) + assert medrecord.select_edges( + edge().attribute("integer").equal(edge().attribute("float").round()) + ) == [2] + assert medrecord.select_edges( + edge().attribute("float").not_equal(edge().attribute("float").round()) + ) == [2] # Attribute compare to attribute ceil - assert medrecord.select_edges(edge().attribute("integer").equal(edge().attribute("float").ceil())) == [2] - assert medrecord.select_edges(edge().attribute("float").not_equal(edge().attribute("float").ceil())) == [2] + assert medrecord.select_edges( + edge().attribute("integer").equal(edge().attribute("float").ceil()) + ) == [2] + assert medrecord.select_edges( + edge().attribute("float").not_equal(edge().attribute("float").ceil()) + ) == [2] # Attribute compare to attribute floor - assert medrecord.select_edges(edge().attribute("integer").equal(edge().attribute("float").floor())) == [] - assert medrecord.select_edges(edge().attribute("float").not_equal(edge().attribute("float").floor())) == [2] + assert ( + medrecord.select_edges( + edge().attribute("integer").equal(edge().attribute("float").floor()) + ) + == [] + ) + assert medrecord.select_edges( + edge().attribute("float").not_equal(edge().attribute("float").floor()) + ) == [2] # Attribute compare to attribute abs - assert medrecord.select_edges(edge().attribute("integer").equal(edge().attribute("integer").abs())) == [2] - assert medrecord.select_edges(edge().attribute("integer").not_equal(edge().attribute("integer").abs())) == [] + assert medrecord.select_edges( + edge().attribute("integer").equal(edge().attribute("integer").abs()) + ) == [2] + assert ( + medrecord.select_edges( + edge().attribute("integer").not_equal(edge().attribute("integer").abs()) + ) + == [] + ) # Attribute compare to attribute sqrt - assert medrecord.select_edges(edge().attribute("integer").equal(edge().attribute("integer").sqrt())) == [2] - assert medrecord.select_edges(edge().attribute("integer").not_equal(edge().attribute("integer").sqrt())) == [] + assert medrecord.select_edges( + edge().attribute("integer").equal(edge().attribute("integer").sqrt()) + ) == [2] + assert ( + medrecord.select_edges( + edge() + .attribute("integer") + .not_equal(edge().attribute("integer").sqrt()) + ) + == [] + ) # Attribute compare to attribute trim - assert medrecord.select_edges(edge().attribute("sed").equal(edge().attribute("dolor").trim())) == [0] + assert medrecord.select_edges( + edge().attribute("sed").equal(edge().attribute("dolor").trim()) + ) == [0] # Attribute compare to attribute trim_start - assert medrecord.select_edges(edge().attribute("sed").equal(edge().attribute("dolor").trim_start())) == [] + assert ( + medrecord.select_edges( + edge().attribute("sed").equal(edge().attribute("dolor").trim_start()) + ) + == [] + ) # Attribute compare to attribute trim_end - assert medrecord.select_edges(edge().attribute("sed").equal(edge().attribute("dolor").trim_end())) == [] + assert ( + medrecord.select_edges( + edge().attribute("sed").equal(edge().attribute("dolor").trim_end()) + ) + == [] + ) # Attribute compare to attribute lowercase - assert medrecord.select_edges(edge().attribute("sed").equal(edge().attribute("test").lowercase())) == [0] + assert medrecord.select_edges( + edge().attribute("sed").equal(edge().attribute("test").lowercase()) + ) == [0] # Attribute compare to attribute uppercase - assert medrecord.select_edges(edge().attribute("sed").equal(edge().attribute("test").uppercase())) == [] + assert ( + medrecord.select_edges( + edge().attribute("sed").equal(edge().attribute("test").uppercase()) + ) + == [] + ) diff --git a/medmodels/medrecord/tests/test_schema.py b/medmodels/medrecord/tests/test_schema.py index 3dfaa342..e4a72064 100644 --- a/medmodels/medrecord/tests/test_schema.py +++ b/medmodels/medrecord/tests/test_schema.py @@ -16,7 +16,17 @@ def setUp(self) -> None: self.schema = create_medrecord().schema def test_groups(self) -> None: - assert sorted(["diagnosis", "drug", "patient_diagnosis", "patient_drug", "patient_procedure", "patient", "procedure"]) == sorted(self.schema.groups) + assert sorted( + [ + "diagnosis", + "drug", + "patient_diagnosis", + "patient_drug", + "patient_procedure", + "patient", + "procedure", + ] + ) == sorted(self.schema.groups) def test_group(self) -> None: assert isinstance(self.schema.group("patient"), mr.GroupSchema) # pyright: ignore[reportUnnecessaryIsInstance] @@ -39,10 +49,16 @@ def setUp(self) -> None: self.schema = create_medrecord().schema def test_nodes(self) -> None: - assert self.schema.group("patient").nodes == {"age": (mr.Int(), mr.AttributeType.Continuous), "gender": (mr.String(), mr.AttributeType.Categorical)} + assert self.schema.group("patient").nodes == { + "age": (mr.Int(), mr.AttributeType.Continuous), + "gender": (mr.String(), mr.AttributeType.Categorical), + } def test_edges(self) -> None: - assert self.schema.group("patient_diagnosis").edges == {"diagnosis_time": (mr.DateTime(), mr.AttributeType.Temporal), "duration_days": (mr.Option(mr.Float()), mr.AttributeType.Continuous)} + assert self.schema.group("patient_diagnosis").edges == { + "diagnosis_time": (mr.DateTime(), mr.AttributeType.Temporal), + "duration_days": (mr.Option(mr.Float()), mr.AttributeType.Continuous), + } def test_strict(self) -> None: assert True is self.schema.group("patient").strict @@ -60,7 +76,9 @@ def setUp(self) -> None: ) def test_repr(self) -> None: - assert repr(self.attributes_schema) == "{'description': (DataType.String, None)}" + assert ( + repr(self.attributes_schema) == "{'description': (DataType.String, None)}" + ) second_attributes_schema = ( Schema( @@ -77,7 +95,10 @@ def test_repr(self) -> None: .nodes ) - assert repr(second_attributes_schema) == "{'description': (DataType.String, AttributeType.Categorical)}" + assert ( + repr(second_attributes_schema) + == "{'description': (DataType.String, AttributeType.Categorical)}" + ) def test_getitem(self) -> None: assert (mr.String(), None) == self.attributes_schema["description"] @@ -158,14 +179,18 @@ def test_values(self) -> None: assert [(mr.String(), None)] == list(self.attributes_schema.values()) def test_items(self) -> None: - assert [("description", (mr.String(), None))] == list(self.attributes_schema.items()) + assert [("description", (mr.String(), None))] == list( + self.attributes_schema.items() + ) def test_get(self) -> None: assert (mr.String(), None) == self.attributes_schema.get("description") assert None is self.attributes_schema.get("nonexistent") - assert (mr.String(), None) == self.attributes_schema.get("nonexistent", (mr.String(), None)) + assert (mr.String(), None) == self.attributes_schema.get( + "nonexistent", (mr.String(), None) + ) class TestAttributeType(unittest.TestCase): diff --git a/medmodels/treatment_effect/estimate.py b/medmodels/treatment_effect/estimate.py index 65d17fd9..71980781 100644 --- a/medmodels/treatment_effect/estimate.py +++ b/medmodels/treatment_effect/estimate.py @@ -132,25 +132,19 @@ def _check_medrecord(self, medrecord: MedRecord) -> None: f"Patient group {self._treatment_effect._patients_group} not found in " f"the MedRecord. Available groups: {medrecord.groups}" ) - raise ValueError( - msg - ) + raise ValueError(msg) if self._treatment_effect._treatments_group not in medrecord.groups: msg = ( "Treatment group not found in the MedRecord. " f"Available groups: {medrecord.groups}" ) - raise ValueError( - msg - ) + raise ValueError(msg) if self._treatment_effect._outcomes_group not in medrecord.groups: msg = ( "Outcome group not found in the MedRecord." f"Available groups: {medrecord.groups}" ) - raise ValueError( - msg - ) + raise ValueError(msg) def _sort_subjects_in_groups( self, medrecord: MedRecord @@ -541,9 +535,7 @@ def hazard_ratio(self, medrecord: MedRecord) -> float: if hazard_control == 0: msg = "Control hazard rate is zero, cannot calculate hazard ratio." - raise ValueError( - msg - ) + raise ValueError(msg) return hazard_treat / hazard_control diff --git a/medmodels/treatment_effect/matching/algorithms/classic_distance_models.py b/medmodels/treatment_effect/matching/algorithms/classic_distance_models.py index 3c0dd961..19970a28 100644 --- a/medmodels/treatment_effect/matching/algorithms/classic_distance_models.py +++ b/medmodels/treatment_effect/matching/algorithms/classic_distance_models.py @@ -36,9 +36,7 @@ def nearest_neighbor( """ if treated_set.shape[0] * number_of_neighbors > control_set.shape[0]: msg = "The treated set is too large for the given number of neighbors." - raise ValueError( - msg - ) + raise ValueError(msg) if not covariates: covariates = treated_set.columns diff --git a/medmodels/treatment_effect/tests/test_temporal_analysis.py b/medmodels/treatment_effect/tests/test_temporal_analysis.py index a856c78f..35ac6b8c 100644 --- a/medmodels/treatment_effect/tests/test_temporal_analysis.py +++ b/medmodels/treatment_effect/tests/test_temporal_analysis.py @@ -164,7 +164,9 @@ def test_find_reference_time(self) -> None: assert edge == 0 def test_invalid_find_reference_time(self) -> None: - with pytest.raises(ValueError, match="Time attribute not found in the edge attributes"): + with pytest.raises( + ValueError, match="Time attribute not found in the edge attributes" + ): find_reference_edge( self.medrecord, node_index="P1", @@ -174,7 +176,9 @@ def test_invalid_find_reference_time(self) -> None: ) node_index = "P2" - with pytest.raises(ValueError, match=f"No edge found for node {node_index} in this MedRecord"): + with pytest.raises( + ValueError, match=f"No edge found for node {node_index} in this MedRecord" + ): find_reference_edge( self.medrecord, node_index=node_index, @@ -211,7 +215,9 @@ def test_node_in_time_window(self) -> None: assert not node_found2 def test_invalid_node_in_time_window(self) -> None: - with pytest.raises(ValueError, match="Time attribute not found in the edge attributes"): + with pytest.raises( + ValueError, match="Time attribute not found in the edge attributes" + ): find_node_in_time_window( self.medrecord, subject_index="P3", diff --git a/medmodels/treatment_effect/tests/test_treatment_effect.py b/medmodels/treatment_effect/tests/test_treatment_effect.py index 0c6324d7..287a409f 100644 --- a/medmodels/treatment_effect/tests/test_treatment_effect.py +++ b/medmodels/treatment_effect/tests/test_treatment_effect.py @@ -198,20 +198,51 @@ def assert_treatment_effects_equal( assert treatment_effect1._outcomes_group == treatment_effect2._outcomes_group assert treatment_effect1._patients_group == treatment_effect2._patients_group assert treatment_effect1._time_attribute == treatment_effect2._time_attribute - assert treatment_effect1._washout_period_days == treatment_effect2._washout_period_days - assert treatment_effect1._washout_period_reference == treatment_effect2._washout_period_reference + assert ( + treatment_effect1._washout_period_days == treatment_effect2._washout_period_days + ) + assert ( + treatment_effect1._washout_period_reference + == treatment_effect2._washout_period_reference + ) assert treatment_effect1._grace_period_days == treatment_effect2._grace_period_days - assert treatment_effect1._grace_period_reference == treatment_effect2._grace_period_reference - assert treatment_effect1._follow_up_period_days == treatment_effect2._follow_up_period_days - assert treatment_effect1._follow_up_period_reference == treatment_effect2._follow_up_period_reference - assert treatment_effect1._outcome_before_treatment_days == treatment_effect2._outcome_before_treatment_days - assert treatment_effect1._filter_controls_operation == treatment_effect2._filter_controls_operation + assert ( + treatment_effect1._grace_period_reference + == treatment_effect2._grace_period_reference + ) + assert ( + treatment_effect1._follow_up_period_days + == treatment_effect2._follow_up_period_days + ) + assert ( + treatment_effect1._follow_up_period_reference + == treatment_effect2._follow_up_period_reference + ) + assert ( + treatment_effect1._outcome_before_treatment_days + == treatment_effect2._outcome_before_treatment_days + ) + assert ( + treatment_effect1._filter_controls_operation + == treatment_effect2._filter_controls_operation + ) assert treatment_effect1._matching_method == treatment_effect2._matching_method - assert treatment_effect1._matching_essential_covariates == treatment_effect2._matching_essential_covariates - assert treatment_effect1._matching_one_hot_covariates == treatment_effect2._matching_one_hot_covariates + assert ( + treatment_effect1._matching_essential_covariates + == treatment_effect2._matching_essential_covariates + ) + assert ( + treatment_effect1._matching_one_hot_covariates + == treatment_effect2._matching_one_hot_covariates + ) assert treatment_effect1._matching_model == treatment_effect2._matching_model - assert treatment_effect1._matching_number_of_neighbors == treatment_effect2._matching_number_of_neighbors - assert treatment_effect1._matching_hyperparam == treatment_effect2._matching_hyperparam + assert ( + treatment_effect1._matching_number_of_neighbors + == treatment_effect2._matching_number_of_neighbors + ) + assert ( + treatment_effect1._matching_hyperparam == treatment_effect2._matching_hyperparam + ) class TestTreatmentEffect(unittest.TestCase): @@ -264,7 +295,9 @@ def test_check_medrecord(self) -> None: .build() ) - with pytest.raises(ValueError, match="Treatment group not found in the MedRecord"): + with pytest.raises( + ValueError, match="Treatment group not found in the MedRecord" + ): tee.estimate._check_medrecord(medrecord=self.medrecord) tee2 = ( @@ -274,7 +307,9 @@ def test_check_medrecord(self) -> None: .build() ) - with pytest.raises(ValueError, match="Outcome group not found in the MedRecord"): + with pytest.raises( + ValueError, match="Outcome group not found in the MedRecord" + ): tee2.estimate._check_medrecord(medrecord=self.medrecord) patient_group = "subjects" @@ -286,7 +321,10 @@ def test_check_medrecord(self) -> None: .build() ) - with pytest.raises(ValueError, match=f"Patient group {patient_group} not found in the MedRecord"): + with pytest.raises( + ValueError, + match=f"Patient group {patient_group} not found in the MedRecord", + ): tee3.estimate._check_medrecord(medrecord=self.medrecord) def test_find_treated_patients(self) -> None: @@ -551,7 +589,9 @@ def test_outcome_before_treatment(self) -> None: .build() ) - with pytest.raises(ValueError, match="No outcomes found in the MedRecord for group "): + with pytest.raises( + ValueError, match="No outcomes found in the MedRecord for group " + ): tee3._find_outcomes(medrecord=self.medrecord, treated_group=treated_group) def test_filter_controls(self) -> None: @@ -633,7 +673,9 @@ def test_find_controls(self) -> None: self.assertEqual(control_outcome_true, {"P1", "P4", "P7"}) self.assertEqual(control_outcome_false, {"P5", "P8", "P9"}) - with pytest.raises(ValueError, match="No patients found for control groups in this MedRecord."): + with pytest.raises( + ValueError, match="No patients found for control groups in this MedRecord." + ): tee._find_controls( self.medrecord, control_group=patients - treated_group, @@ -650,7 +692,9 @@ def test_find_controls(self) -> None: self.medrecord.add_group("Headache") - with pytest.raises(ValueError, match="No outcomes found in the MedRecord for group."): + with pytest.raises( + ValueError, match="No outcomes found in the MedRecord for group." + ): tee2._find_controls( self.medrecord, control_group=patients - treated_group, diff --git a/medmodels/treatment_effect/treatment_effect.py b/medmodels/treatment_effect/treatment_effect.py index 9cce65ad..133174ae 100644 --- a/medmodels/treatment_effect/treatment_effect.py +++ b/medmodels/treatment_effect/treatment_effect.py @@ -256,9 +256,7 @@ def _find_treated_patients(self, medrecord: MedRecord) -> Set[NodeIndex]: ) if not treated_group: msg = "No patients found for the treatment groups in this MedRecord." - raise ValueError( - msg - ) + raise ValueError(msg) return treated_group @@ -294,9 +292,7 @@ def _find_outcomes( outcomes = medrecord.nodes_in_group(self._outcomes_group) if not outcomes: msg = f"No outcomes found in the MedRecord for group {self._outcomes_group}" - raise ValueError( - msg - ) + raise ValueError(msg) for outcome in outcomes: nodes_to_check = set( @@ -463,9 +459,7 @@ def _find_controls( outcomes = medrecord.nodes_in_group(self._outcomes_group) if not outcomes: msg = f"No outcomes found in the MedRecord for group {self._outcomes_group}" - raise ValueError( - msg - ) + raise ValueError(msg) # Finding the patients that had the outcome in the control group for outcome in outcomes: