Skip to content

Commit

Permalink
fix float nan comparison
Browse files Browse the repository at this point in the history
This change also adds minor docstrings fixes and bumps pre-commit blac
version.
  • Loading branch information
Gobot1234 authored Apr 23, 2022
1 parent ac96d82 commit 6f7d706
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/betterproto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def _parse_float(value: Any) -> float:
Parameters
----------
value : Any
value: Any
Value to parse
Returns
Expand All @@ -456,20 +456,19 @@ def _dump_float(value: float) -> Union[float, str]:
Parameters
----------
value : float
value: float
Value to dump
Returns
-------
Union[float, str]
Dumped valid, either a float or the strings
"Infinity" or "-Infinity"
Dumped value, either a float or the strings
"""
if value == float("inf"):
return INFINITY
if value == -float("inf"):
return NEG_INFINITY
if value == float("nan"):
if isinstance(value, float) and math.isnan(value):
return NAN
return value

Expand Down

0 comments on commit 6f7d706

Please sign in to comment.