Skip to content

Commit 122830a

Browse files
author
hhourston
committed
add nan case to utils.round_to_int()
1 parent 6f93d24 commit 122830a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pycurrents_ADCP_processing/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ def geospatial_vertical_extrema(orientation: str, sensor_depth: float, distance:
128128
return np.round(geospatial_vertical_min, num_decimals), np.round(geospatial_vertical_max, num_decimals)
129129

130130

131-
def round_to_int(x):
131+
def round_to_int(x: float):
132132
"""
133133
Use instead of numpy.round(), which uses "banker's rounding" which rounds 1.5 and 2.5 to 2 !!
134134
"""
135-
return int(np.ceil(x)) if x % 1 >= .5 else int(np.floor(x))
135+
if not np.isnan(x):
136+
return int(np.ceil(x)) if x % 1 >= .5 else int(np.floor(x))
137+
else:
138+
return np.nan

0 commit comments

Comments
 (0)