Missings.jl icon indicating copy to clipboard operation
Missings.jl copied to clipboard

Add `isless` variant where `missing` is smallest

Open bkamins opened this issue 3 years ago • 10 comments

The definitions to make missing smallest would be

isless2(::Missing, ::Missing) = false
isless2(::Missing, ::Any) = true
isless2(::Any, ::Missing) = false
isless2(x, y) = isless(x, y)

@nalimilan - the question is what should be the name of this function (as usual this is the hardest part).

Also a question is if Missings.jl should export it (I think it is OK to export it if we find a good name)

bkamins avatar Feb 17 '22 09:02 bkamins

islessmissingsmallest or islessmissingfirst would be explicit though a bit long...

nalimilan avatar Feb 17 '22 10:02 nalimilan

This is my fear. Let us ask on Slack.

bkamins avatar Feb 17 '22 11:02 bkamins

let's start by removing isless, since it is the default value missingassmallest missingissmallest

sprmnt21 avatar Feb 17 '22 15:02 sprmnt21

We could also say missingisless since this function really does this: consider that missing is less than all other values.

nalimilan avatar Feb 17 '22 16:02 nalimilan

missingless? (without s in the middle)

bkamins avatar Feb 17 '22 16:02 bkamins

it sounds like a play on words (or is it? I like it). missingless could be read as no missing

sprmnt21 avatar Feb 17 '22 18:02 sprmnt21

You guys obviously know way more than me with regards of design and philosophy of these packages, but I thought of this operation as sort acting in somehow in combination with skipmissing. I don't know if that's the right approach an what consequences you have from this, but something like sort(df, :A, rev = true, skipmissing = true) was the operation I was hoping to have.

alejandromerchan avatar Feb 17 '22 19:02 alejandromerchan

The approach we are discussing is more general and would allow you to sort any collection, e.g. a vector in exactly the same way.

bkamins avatar Feb 17 '22 20:02 bkamins

Any objections to missingisless?

BTW, since the main use case is to do sort(x, lt=missingisless, rev=true), we could directly provide a function which reverses the order. But I don't have a good name for that (missingisnotgreater?)

nalimilan avatar Mar 29 '22 19:03 nalimilan

missingisnotgreater feels unclear.

missingisless seems OK.

bkamins avatar Mar 29 '22 19:03 bkamins