Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 0.0 value floats #452

Merged
merged 1 commit into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flytekit/core/type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,9 @@ def to_python_value(self, ctx: FlyteContext, lv: Literal, expected_python_type:


def _check_and_covert_float(lv: Literal) -> float:
if lv.scalar.primitive.float_value:
if lv.scalar.primitive.float_value is not None:
return lv.scalar.primitive.float_value
elif lv.scalar.primitive.integer:
elif lv.scalar.primitive.integer is not None:
return float(lv.scalar.primitive.integer)
raise RuntimeError(f"Cannot convert literal {lv} to float")

Expand Down
10 changes: 10 additions & 0 deletions tests/flytekit/unit/core/test_type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,13 @@ def test_protos():
l0 = Literal(scalar=Scalar(primitive=Primitive(integer=4)))
with pytest.raises(AssertionError):
TypeEngine.to_python_value(ctx, l0, errors_pb2.ContainerError)


def test_zero_floats():
ctx = FlyteContext.current_context()

l0 = Literal(scalar=Scalar(primitive=Primitive(integer=0)))
l1 = Literal(scalar=Scalar(primitive=Primitive(float_value=0.0)))

assert TypeEngine.to_python_value(ctx, l0, float) == 0
assert TypeEngine.to_python_value(ctx, l1, float) == 0