Skip to content

Commit 5f10714

Browse files
committed
[util] Handle cardinality empty tuple edgecase
1 parent 019c87b commit 5f10714

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

odml/util.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ def format_cardinality(in_val):
2727
exc_msg = "Can only assign positive single int or int-tuples of the format '(min, max)'"
2828

2929
# Empty values reset the cardinality to None.
30-
if not in_val or in_val == (None, None):
30+
if not in_val:
31+
return None
32+
33+
# Catch tuple edge cases (0, 0); (None, None); (0, None); (None, 0)
34+
if isinstance(in_val, tuple) and len(in_val) > 1 and not in_val[0] and not in_val[1]:
3135
return None
3236

3337
# Providing a single integer sets the maximum value in a tuple.

test/test_util.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ def test_format_cardinality(self):
1616
self.assertIsNone(format_cardinality({}))
1717
self.assertIsNone(format_cardinality(""))
1818
self.assertIsNone(format_cardinality(()))
19+
20+
# Test empty tuple edge cases
1921
self.assertIsNone(format_cardinality((None, None)))
22+
self.assertIsNone(format_cardinality((0, 0)))
23+
self.assertIsNone(format_cardinality((None, 0)))
24+
self.assertIsNone(format_cardinality((0, None)))
2025

2126
# Test single int max set
2227
self.assertEqual(format_cardinality(10), (None, 10))

0 commit comments

Comments
 (0)