Skip to content

Commit

Permalink
add nan case to utils.round_to_int()
Browse files Browse the repository at this point in the history
  • Loading branch information
hhourston committed Feb 3, 2024
1 parent 6f93d24 commit 122830a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pycurrents_ADCP_processing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ def geospatial_vertical_extrema(orientation: str, sensor_depth: float, distance:
return np.round(geospatial_vertical_min, num_decimals), np.round(geospatial_vertical_max, num_decimals)


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

0 comments on commit 122830a

Please sign in to comment.