Skip to content

Commit

Permalink
Added comments to get_sibling_section
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed Feb 9, 2024
1 parent 61c6e14 commit 9d90031
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions simulationdataschema/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ def get_sibling_section(
Returns:
sibling_section (ArchiveSection): The sibling_section to be returned.
"""
# Check if the parent of section exists
if section.m_parent is None:
logger.warning("Could not find the parent of the section.")
return

# Check if the sibling_section exists in the parent of section
if not section.m_parent.m_xpath(sibling_section_name):
logger.warning("Could not find the section.m_parent.sub_section.")
return
sibling_section = getattr(section.m_parent, sibling_section_name)

# If the sibling_section is a list, return the element `index_sibling` of that list
if isinstance(sibling_section, list):
if len(sibling_section) == 0:
logger.warning("The sub_section is empty.")
Expand All @@ -68,6 +73,7 @@ def get_sibling_section(
logger.warning("The index of the sub_section is out of range.")
return
return sibling_section[index_sibling]
# If the sibling_section is a single section, return the sibling_section itself
elif isinstance(sibling_section, ArchiveSection):
return sibling_section
return

0 comments on commit 9d90031

Please sign in to comment.