diff --git a/cimsparql/parse_xml.py b/cimsparql/parse_xml.py index 4f674b8e..537c49c6 100644 --- a/cimsparql/parse_xml.py +++ b/cimsparql/parse_xml.py @@ -1,6 +1,7 @@ import collections import gzip import re +from functools import cached_property from pathlib import Path from typing import Callable, Dict, Iterable, List, Optional, Tuple, Union from zipfile import ZipFile @@ -319,20 +320,23 @@ def __str__(self) -> str: file_desc = ", ".join([f"{profile}: {path.stem}" for profile, path in self.paths.items()]) return f"" - @property + @cached_property def voltage(self) -> pd.DataFrame: return self._parser["sv"].parse("SvVoltage").set_index("mrid") - @property + @cached_property def tap_steps(self) -> pd.DataFrame: return self._parser["sv"].parse("SvTapStep").set_index("mrid") + @cached_property def bus_data(self, *args, **kwargs) -> pd.DataFrame: return self._parser["tp"].parse("TopologicalNode").set_index("mrid") + @cached_property def terminal(self, *args, **kwargs) -> pd.DataFrame: return self._parser["tp"].parse("Terminal").set_index("mrid") + @cached_property def powerflow(self, *args, **kwargs) -> pd.DataFrame: return self._parser["sv"].parse("SvPowerFlow").set_index("mrid") diff --git a/tests/test_parse_xml.py b/tests/test_parse_xml.py index b42f3c9f..12cc4de5 100644 --- a/tests/test_parse_xml.py +++ b/tests/test_parse_xml.py @@ -34,7 +34,7 @@ def sv_tp_cim(profiles: List[str]) -> SvTpCimXml: @pytest.fixture(scope="module") def bus_data(sv_tp_cim) -> pd.DataFrame: - return sv_tp_cim.bus_data() + return sv_tp_cim.bus_data @pytest.fixture(scope="module") @@ -57,25 +57,22 @@ def test_parse_sv_tp_cim_xml_bus_data(bus_data: pd.DataFrame): def test_parse_sv_tp_cim_xml_terminal(sv_tp_cim: SvTpCimXml): - assert sv_tp_cim.terminal().shape == (4, 2) + assert sv_tp_cim.terminal.shape == (4, 2) def test_parse_sv_tp_cim_xml_powerflow(sv_tp_cim: SvTpCimXml): - powerflow = sv_tp_cim.powerflow() - assert powerflow.shape == (4, 2) - assert (powerflow.dtypes == float).all() + assert sv_tp_cim.powerflow.shape == (4, 2) + assert (sv_tp_cim.powerflow.dtypes == float).all() def test_parse_sv_tp_cim_xml_voltage(sv_tp_cim: SvTpCimXml): - voltage = sv_tp_cim.voltage - assert voltage.shape == (4, 2) - assert (voltage.dtypes == float).all() + assert sv_tp_cim.voltage.shape == (4, 2) + assert (sv_tp_cim.voltage.dtypes == float).all() def test_parse_sv_tp_cim_xml_tap_step(sv_tp_cim: SvTpCimXml): - tap_steps = sv_tp_cim.tap_steps - assert tap_steps.shape == (4, 1) - assert (tap_steps.dtypes == int).all() + assert sv_tp_cim.tap_steps.shape == (4, 1) + assert (sv_tp_cim.tap_steps.dtypes == int).all() def test_parse_cim_file():