Skip to content

Commit

Permalink
fix: make Number vals type float only
Browse files Browse the repository at this point in the history
  • Loading branch information
rick-jennings committed Oct 10, 2024
1 parent 9b30676 commit 02f5d8b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
4 changes: 2 additions & 2 deletions phable/kinds.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ class Number:
[here](https://project-haystack.org/doc/docHaystack/Kinds#number).
Parameters:
val: Integer or floating point value.
val: Floating point value.
unit:
Optional unit of measurement defined in Project Haystack's standard unit
database [here](https://project-haystack.org/doc/docHaystack/Units).
**Note**: Phable does not validate a defined unit at this time.
"""

val: int | float
val: float
unit: str | None = None

def __str__(self):
Expand Down
5 changes: 1 addition & 4 deletions phable/parsers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _dict_to_json(row: dict[str, Any]) -> dict[str, Any]:
return parsed_row


def _number_to_json(num: Number) -> int | float | dict[str, str | float]:
def _number_to_json(num: Number) -> float | dict[str, str | float]:
if num.unit is None:
return num.val
return {"_kind": "number", "val": num.val, "unit": num.unit}
Expand Down Expand Up @@ -169,9 +169,6 @@ def _parse_number(d: dict[str, str]) -> Number:
unit = d.get("unit", None)
num = float(d["val"])

if num % 1 == 0:
num = int(num)

return Number(num, unit)


Expand Down

0 comments on commit 02f5d8b

Please sign in to comment.