Skip to content

DYN-8693 Fix List.SortIndexByValue to accept integers and mixed numeric types#17053

Open
Copilot wants to merge 3 commits into
masterfrom
copilot/fix-sort-index-by-value
Open

DYN-8693 Fix List.SortIndexByValue to accept integers and mixed numeric types#17053
Copilot wants to merge 3 commits into
masterfrom
copilot/fix-sort-index-by-value

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 15, 2026

Purpose

Fixes List.SortIndexByValue silently failing when passed integers or mixed numeric lists. The parameter was typed as List<double>, causing Dynamo's type coercion to fail on common use cases. Resolves DYN-8693.

Declarations

Check these if you believe they are true

Release Notes

Fixed List.SortIndexByValue to correctly accept integers and mixed numeric types (int, double, float). Previously, passing integers would fail silently due to type coercion limitations with List<double>.

Reviewers

@johnpierson

FYIs

N/A

…rable types

Agent-Logs-Url: https://github.com/DynamoDS/Dynamo/sessions/b0cc73a2-9ed4-4556-bc2b-38de3c0f3bae

Co-authored-by: johnpierson <15744724+johnpierson@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix List.SortIndexByValue to accept integer types DYN-8693 Fix List.SortIndexByValue to accept integers and mixed numeric types Apr 15, 2026
Copilot AI requested a review from johnpierson April 15, 2026 19:41
@johnpierson johnpierson marked this pull request as ready for review April 15, 2026 19:43
Copilot AI review requested due to automatic review settings April 15, 2026 19:43
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the ticket for this pull request: https://jira.autodesk.com/browse/DYN-8693

Copy link
Copy Markdown
Member

@johnpierson johnpierson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks awesome to me mr @copilot

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates DSCore.List.SortIndexByValue to support integer and mixed numeric inputs (and other object-typed values) by switching to the shared ObjectComparer, aligning behavior with DSCore.List.Sort.

Changes:

  • Changed SortIndexByValue input from List<double> to IEnumerable<object> and replaced the custom sorting logic with ObjectComparer.
  • Removed a redundant/no-op OrderBy from the prior implementation.
  • Updated and expanded unit tests to cover integer and mixed numeric inputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Libraries/CoreNodes/List.cs Broadens accepted input types and uses ObjectComparer for consistent cross-type ordering.
test/Libraries/CoreNodesTests/ListTests.cs Updates existing test to List<object> and adds new cases for integer and mixed numeric inputs.

Comment thread src/Libraries/CoreNodes/List.cs Outdated
Comment on lines +247 to +252
public static IEnumerable SortIndexByValue(IEnumerable<object> list)
{
List<Tuple<int, double>> tupleList = new List<Tuple<int, double>>();
for (int i = 0; i < list.Count; i++)
{
tupleList.Add(new Tuple<int, double>(i, list[i]));
}
tupleList = tupleList.OrderBy(x => x.Item2).ToList();
IEnumerable<int> newList = tupleList.OrderBy(x => x.Item2).Select(y => y.Item1);
IEnumerable<int> newList = list
.Select((value, index) => new Tuple<int, object>(index, value))
.OrderBy(x => x.Item2, new ObjectComparer())
.Select(y => y.Item1);
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the parameter type from List<double> to IEnumerable<object> is a source/binary breaking change for any compiled callers (e.g., List<double>/IEnumerable<double> can’t be passed to IEnumerable<object> because covariance doesn’t apply to value types). Consider preserving the old signature (e.g., keep SortIndexByValue(List<double>) and delegate to the new implementation, or change the new API to accept non-generic IEnumerable/IList for broader compatibility) to avoid breaking external consumers while still fixing Dynamo’s type coercion issue.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this not an issue?

Copy link
Copy Markdown
Member

@mjkkirschner mjkkirschner Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to also consider the performance and memory impact of this change on large lists.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the parameter type from List<double> to IEnumerable<object> is a source/binary breaking change for any compiled callers (e.g., List<double>/IEnumerable<double> can’t be passed to IEnumerable<object> because covariance doesn’t apply to value types). Consider preserving the old signature (e.g., keep SortIndexByValue(List<double>) and delegate to the new implementation, or change the new API to accept non-generic IEnumerable/IList for broader compatibility) to avoid breaking external consumers while still fixing Dynamo’s type coercion issue.

@copilot do this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the parameter to IList (non-generic) in b69fa14. This is backward-compatible — List<double>, List<int>, List<object> all implement IList, so no breaking change for existing compiled callers. This is also the dominant pattern used by virtually every other method in List.cs.

On performance: IList.Cast<object>() produces a lazy iterator (no extra allocation beyond a single thin wrapper), so the memory and time complexity remain the same O(n log n) / O(n) as before — only the boxing cost for value-type elements is added, which is equivalent to what List.Sort(IEnumerable<object>) does.

Also fixed the stable-sort test assertions for equal-value inputs ({ 8, 4, 2, 4, 0 }[4, 2, 1, 3, 0], not [4, 2, 3, 1, 0]) and updated the integer test to use List<int> directly.

Comment thread test/Libraries/CoreNodesTests/ListTests.cs Outdated
Comment thread test/Libraries/CoreNodesTests/ListTests.cs Outdated
…t assertions

Agent-Logs-Url: https://github.com/DynamoDS/Dynamo/sessions/6ce82cbe-6eef-4038-8232-10aa356ec69f

Co-authored-by: johnpierson <15744724+johnpierson@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

List.SortIndexByValue only accepts double types

4 participants