Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/zepben/evolve/model/cim/iec61970/base/core/equipment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Zeppelin Bend Pty Ltd
# Copyright 2025 Zeppelin Bend Pty Ltd
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
Expand Down Expand Up @@ -132,19 +132,19 @@ def num_substations(self) -> int:
"""
Returns The number of `zepben.evolve.cim.iec61970.base.core.substation.Substation`s associated with this `Equipment`
"""
return len(_of_type(self._equipment_containers, Substation))
return len(list(_of_type(self._equipment_containers, Substation)))

def num_sites(self) -> int:
"""
Returns The number of `Site`s associated with this `Equipment`
"""
return len(_of_type(self._equipment_containers, Site))
return len(list(_of_type(self._equipment_containers, Site)))

def num_normal_feeders(self) -> int:
"""
Returns The number of normal `Feeder`s associated with this `Equipment`
"""
return len(_of_type(self._equipment_containers, Feeder))
return len(list(_of_type(self._equipment_containers, Feeder)))

def num_usage_points(self) -> int:
"""
Expand Down Expand Up @@ -358,9 +358,6 @@ def clear_operational_restrictions(self) -> Equipment:
return self


def _of_type(containers: Optional[List[EquipmentContainer]], ectype: Type[TEquipmentContainer]) -> List[TEquipmentContainer]:
if containers:
return [ec for ec in containers if isinstance(ec, ectype)]
else:
return []
def _of_type(containers: Optional[List[EquipmentContainer]], ectype: Type[TEquipmentContainer]) -> Generator[TEquipmentContainer, None, None]:
yield from (ec for ec in containers if isinstance(ec, ectype)) if containers is not None else {}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Zeppelin Bend Pty Ltd
# Copyright 2025 Zeppelin Bend Pty Ltd
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
Expand Down Expand Up @@ -41,7 +41,7 @@ def diagonal(self) -> Generator[PhaseImpedanceData, None, None]:
"""
Get only the diagonal elements of the matrix, i.e toPhase == fromPhase.
"""
return ngen([pid for pid in self._data if pid.from_phase == pid.to_phase])
return ngen(pid for pid in self._data if pid.from_phase == pid.to_phase)

def num_data(self):
"""Return the number of :class:`PhaseImpedanceData` associated with this :class:`PerLengthPhaseImpedance`."""
Expand Down
4 changes: 1 addition & 3 deletions src/zepben/evolve/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ def nlen(sized: Optional[Sized]) -> int:


def ngen(collection: Optional[Iterable[T]]) -> Generator[T, None, None]:
if collection:
for item in collection:
yield item
yield from collection or {}


def is_none_or_empty(sized: Optional[Sized]) -> bool:
Expand Down