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 RangeSet.__len__ when defined by floats #3119

Merged
merged 2 commits into from
Feb 2, 2024
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
2 changes: 1 addition & 1 deletion pyomo/core/base/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -2668,7 +2668,7 @@ def __len__(self):
if r.start == r.end:
return 1
else:
return (r.end - r.start) // r.step + 1
return int((r.end - r.start) // r.step) + 1
else:
return sum(1 for _ in self)

Expand Down
4 changes: 4 additions & 0 deletions pyomo/core/tests/unit/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,10 @@ def __len__(self):
# Test types that cannot be case to set
self.assertNotEqual(SetOf({3}), 3)

# Test floats
self.assertEqual(RangeSet(0.0, 2.0), RangeSet(0.0, 2.0))
self.assertEqual(RangeSet(0.0, 2.0), RangeSet(0, 2))

def test_inequality(self):
self.assertTrue(SetOf([1, 2, 3]) <= SetOf({1, 2, 3}))
self.assertFalse(SetOf([1, 2, 3]) < SetOf({1, 2, 3}))
Expand Down
Loading