Forum Discussion

routineMetric0's avatar
routineMetric0
Regular Visitor
3 years ago

List.RemoveItems Bug related to Number.NaN

Just ran into this and I think it's a bug. Say you have a simple list with NaNs in it and you want to remove them. Neither List.RemoveItems() nor List.RemoveMatchingItems() will remove the NaNs. See repro below:

 

    let

        Source = {3, 540, 309, 30, Number.NaN, 384},
        RemoveNan = List.RemoveItems(Source, {Number.NaN})

    in

        RemoveNan

 

Now, I know this could be solved via List.Select(Source, each not Number.IsNaN(_)), but this definitely seems like inconsistent, unintended, or unexpected behavior. See another repro using Number.PositiveInfinity where it works like you would expect.

 

    let

        Source = {3, 540, 309, 30, Number.PositiveInfinity, 384},
        RemovePosInfinity = List.RemoveItems(Source, {Number.PositiveInfinity})

    in

        RemovePosInfinity

 

I've also tested this simple code with Number.NegativeInfinity, Number.PI, Number.E, Number.Epsilon, and null, and for everything but Number.NaN, List.RemoveItems/List.RemoveMatchingItems works.

3 Replies