Skip to content

Commit 39cf290

Browse files
committed
Updated SorterAgeBased to handle single or null age inputs
1 parent 537e6ab commit 39cf290

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

map2loop/sorter.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,24 @@ def sort(
155155
"""
156156
logger.info("Calling age based sorter")
157157
sorted_units = units.copy()
158-
# Calculate mean age
159158
if "minAge" in units.columns and "maxAge" in units.columns:
160159
sorted_units["meanAge"] = sorted_units.apply(
161-
lambda row: (row["minAge"] + row["maxAge"]) / 2.0, axis=1
160+
lambda row: (
161+
row["maxAge"]
162+
if ((row["minAge"] == 0 or pandas.isna(row["minAge"])) and row["maxAge"] > 1)
163+
else (
164+
row["minAge"]
165+
if (
166+
(row["maxAge"] == 0 or pandas.isna(row["maxAge"])) and row["minAge"] > 1
167+
)
168+
else (
169+
(row["minAge"] + row["maxAge"]) / 2.0
170+
if pandas.notna(row["minAge"]) and pandas.notna(row["maxAge"])
171+
else 0
172+
)
173+
)
174+
),
175+
axis=1,
162176
)
163177
else:
164178
sorted_units["meanAge"] = 0

0 commit comments

Comments
 (0)