<#1428 explicitly handle integers for untyped dict...
# flyte-github
a
#1428 explicitly handle integers for untyped dict type Pull request opened by cosmicBboy fixes #3158 Signed-off-by: Niels Bantilan niels.bantilan@gmail.com TL;DR Protobuf <> json will auto-cast integers to floats when serializing dict values when the type is annotated with a bare
dict
or
typing.Dict
annotation. This will break code that relies on precise types, such as sklearn, which explicitly checks the types of hyperparameter values in Estimator constructor. Type ☑︎ Bug Fix ☐ Feature ☐ Plugin Are all requirements met? ☑︎ Code completed ☑︎ Smoke tested ☑︎ Unit tests added ☐ Code documentation added ☐ Any pending items have an associated Issue Complete description Because the interchange between protobuf and json casts ints to floats, this PR introduces a workaround to handle converting floats to integers by parsing the protobug
struct_pb2.Value
with regex and inferring integers based on its
__repr__
, which actually preserves the integer representation, e.g.
number_value: 100
, but accessing the actual
number_value
attribute will still return a float
assert value.number_value == 100.0
. See here in the protobuf codebase where ints and floats are treated the same. Tracking Issue flyteorg/flyte#3158 Follow-up issue NA flyteorg/flytekit GitHub Actions: lint GitHub Actions: docs GitHub Actions: build-plugins (3.10, flytekit-vaex) GitHub Actions: build-plugins (3.9, flytekit-whylogs) GitHub Actions: build-plugins (3.9, flytekit-vaex) GitHub Actions: build-plugins (3.9, flytekit-sqlalchemy) GitHub Actions: build-plugins (3.9, flytekit-spark) GitHub Actions: build-plugins (3.9, flytekit-snowflake) GitHub Actions: build-plugins (3.9, flytekit-ray) 21 other checks have passed 21/30 successful checks