File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments