Skip to content

Commit 056d2db

Browse files
authored
fix fractional resoure handling for batch (#1089)
1 parent c1ff469 commit 056d2db

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

metaflow/plugins/aws/aws_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ def compute_resource_attributes(decos, compute_deco, resource_defaults):
7979
continue
8080
if my_val is not None and v is not None:
8181
try:
82-
result[k] = str(max(int(my_val or 0), int(v or 0)))
82+
# Use Decimals to compare and convert to string here so
83+
# that numbers that can't be exactly represented as
84+
# floats (e.g. 0.8) still look "nice". We don't care
85+
# about precision more that .001 for resources anyway.
86+
result[k] = str(max(float(my_val or 0), float(v or 0)))
8387
except ValueError:
8488
# Here, we don't have ints so we compare the value and raise
8589
# an exception if not equal

test/unit/test_compute_resource_attributes.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@ def test_compute_resource_attributes():
3939
MockDeco("batch", {"cpu": 1}),
4040
{"cpu": "3"},
4141
)
42-
== {"cpu": "2"}
42+
== {"cpu": "2.0"}
43+
)
44+
45+
# take largest of @resources and @batch if both are present
46+
assert (
47+
compute_resource_attributes(
48+
[MockDeco("resources", {"cpu": 0.83})],
49+
MockDeco("batch", {"cpu": "0.5"}),
50+
{"cpu": "1"},
51+
)
52+
== {"cpu": "0.83"}
4353
)
4454

4555

0 commit comments

Comments
 (0)