-
Notifications
You must be signed in to change notification settings - Fork 669
Fix List.MaximumItem and List.MinimumItem type promotion from Int to Double #17055
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -377,7 +377,15 @@ public static IList Sort(IEnumerable<object> list) | |||||||||||||||||||||||||||||||||
| [IsVisibleInDynamoLibrary(true)] | ||||||||||||||||||||||||||||||||||
| public static object MinimumItem(IEnumerable<object> list) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| return list.Min<object, object>(DoubleConverter); | ||||||||||||||||||||||||||||||||||
| var comparer = new ObjectComparer(); | ||||||||||||||||||||||||||||||||||
| object min = null; | ||||||||||||||||||||||||||||||||||
| foreach (var item in list) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| if (item == null) continue; | ||||||||||||||||||||||||||||||||||
| if (min == null || comparer.Compare(item, min) < 0) | ||||||||||||||||||||||||||||||||||
| min = item; | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+382
to
+386
|
||||||||||||||||||||||||||||||||||
| foreach (var item in list) | |
| { | |
| if (item == null) continue; | |
| if (min == null || comparer.Compare(item, min) < 0) | |
| min = item; | |
| var hasMin = false; | |
| foreach (var item in list) | |
| { | |
| if (item == null) | |
| return null; | |
| if (!hasMin || comparer.Compare(item, min) < 0) | |
| { | |
| min = item; | |
| hasMin = true; | |
| } |
Copilot
AI
Apr 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new loop returns null for an empty list (because min/max never gets assigned). The previous LINQ implementation (Enumerable.Min/Max) throws InvalidOperationException for empty sequences, so this is a behavioral change. If graphs/tests rely on the exception behavior, consider explicitly detecting empties and matching the prior behavior (or document/test the new null return contract).
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -388,6 +388,42 @@ public static void ListMaximumValueMixed() | |
| Assert.AreEqual(66, List.MaximumItem(new List<object> { 8.223, 4, 0.64, 66, 10.2 })); | ||
| } | ||
|
|
||
| [Test] | ||
| [Category("UnitTests")] | ||
| public static void ListMaximumItemPreservesInt64Type() | ||
| { | ||
| var result = List.MaximumItem(new List<object> { 8L, 4L, 0L, 66L, 10L }); | ||
| Assert.IsInstanceOf<long>(result); | ||
| Assert.AreEqual(66L, result); | ||
| } | ||
|
|
||
| [Test] | ||
| [Category("UnitTests")] | ||
| public static void ListMinimumItemPreservesInt64Type() | ||
| { | ||
| var result = List.MinimumItem(new List<object> { 8L, 4L, 0L, 66L, 10L }); | ||
| Assert.IsInstanceOf<long>(result); | ||
| Assert.AreEqual(0L, result); | ||
| } | ||
|
|
||
| [Test] | ||
| [Category("UnitTests")] | ||
| public static void ListMaximumItemPreservesIntType() | ||
| { | ||
| var result = List.MaximumItem(new List<object> { 8, 4, 0, 66, 10 }); | ||
| Assert.IsInstanceOf<int>(result); | ||
| Assert.AreEqual(66, result); | ||
| } | ||
|
|
||
| [Test] | ||
| [Category("UnitTests")] | ||
| public static void ListMinimumItemPreservesIntType() | ||
| { | ||
| var result = List.MinimumItem(new List<object> { 8, 4, 0, 66, 10 }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens when there is a mixed list of doubles and ints? |
||
| Assert.IsInstanceOf<int>(result); | ||
| Assert.AreEqual(0, result); | ||
| } | ||
|
|
||
| [Test] | ||
| [Category("UnitTests")] | ||
| public static void FilterListByMask() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MinimumItem/MaximumItemnow iterate withforeach (var item in list)but don't guard againstlist == null. Iflistis null this will throwNullReferenceException, whereas the previous LINQ implementation would throw anArgumentNullException(and matches other LINQ-based nodes). Add an explicitif (list == null) throw new ArgumentNullException(nameof(list));(or return null if that's the intended node contract) to avoid the regression.