Skip to content

List.MaximumItem breaks on mixed input #9009

@sunfield

Description

@sunfield

Dynamo version

2.0.1.5055

Operating system

Windows 10

What did you do?

Took a list of numbers from a file (so as strings), sorted and converted to number, then tried to find the largest one using List.MaximumItem.

What did you expect to see?

The largest value in the list returned.

What did you see instead?

null, with a warning.

Boiled it down to this:
tonumber

Tests reveal that if some numbers have a decimal separator and others don't, then the output from String.ToNumber is not uniform, which causes problems when using List.MaximumItem, which apparently cannot handle a list that includes e.g. Int and Double.
There is actually test code for this which I imagine should have picked this up:

Assert.AreEqual(66, List.MaximumItem(new List<object> { 8.223, 4, 0.64, 66, 10.2 }));

What's interesting, looking at the source, is that the Max() method, which List.MaximumItem uses, seems to cast its inputs to doubles. My C# is rusty but I'm feel like this should be working?

return list.Max<object, object>(DoubleConverter);

public static double Max(double value1, double value2)

Looking into the DoubleConverter reveals that this was added to fix exactly this problem here #2041, which maybe it did, but perhaps got unfixed with an update..? I'm in over my head at this point, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions