Skip to content

Commit

Permalink
Updated SorterAgeBased to handle single or null age inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ayLa-e committed Dec 18, 2024
1 parent 537e6ab commit 39cf290
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions map2loop/sorter.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,24 @@ def sort(
"""
logger.info("Calling age based sorter")
sorted_units = units.copy()
# Calculate mean age
if "minAge" in units.columns and "maxAge" in units.columns:
sorted_units["meanAge"] = sorted_units.apply(
lambda row: (row["minAge"] + row["maxAge"]) / 2.0, axis=1
lambda row: (
row["maxAge"]
if ((row["minAge"] == 0 or pandas.isna(row["minAge"])) and row["maxAge"] > 1)
else (
row["minAge"]
if (
(row["maxAge"] == 0 or pandas.isna(row["maxAge"])) and row["minAge"] > 1
)
else (
(row["minAge"] + row["maxAge"]) / 2.0
if pandas.notna(row["minAge"]) and pandas.notna(row["maxAge"])
else 0
)
)
),
axis=1,
)
else:
sorted_units["meanAge"] = 0
Expand Down

0 comments on commit 39cf290

Please sign in to comment.