Re: NaN, Null, and Sorting

2012-01-16 Thread Robert Kern
On 1/16/12 10:57 AM, Chris Angelico wrote: On Mon, Jan 16, 2012 at 9:22 PM, Eelco wrote: What you want, conceptually, is a sorted list of the sortable entries, and a seperate list of the unsorted entries. Translated into code, the most pure solution would be to filter out the nanas/nulls in the

Re: NaN, Null, and Sorting

2012-01-16 Thread Chris Angelico
On Mon, Jan 16, 2012 at 9:22 PM, Eelco wrote: > What you want, conceptually, is a > sorted list of the sortable entries, and a seperate list of the > unsorted entries. Translated into code, the most pure solution would > be to filter out the nanas/nulls in their own list first, and then > sort the

Re: NaN, Null, and Sorting

2012-01-16 Thread Eelco
On 13 jan, 20:04, Ethan Furman wrote: > With NaN, it is possible to get a list that will not properly sort: > > --> NaN = float('nan') > --> spam = [1, 2, NaN, 3, NaN, 4, 5, 7, NaN] > --> sorted(spam) > [1, 2, nan, 3, nan, 4, 5, 7, nan] > > I'm constructing a Null object with the semantics that if

Re: NaN, Null, and Sorting

2012-01-13 Thread jmfauth
On 13 jan, 20:04, Ethan Furman wrote: > With NaN, it is possible to get a list that will not properly sort: > > --> NaN = float('nan') > --> spam = [1, 2, NaN, 3, NaN, 4, 5, 7, NaN] > --> sorted(spam) > [1, 2, nan, 3, nan, 4, 5, 7, nan] > > I'm constructing a Null object with the semantics that if

Re: NaN, Null, and Sorting

2012-01-13 Thread Steven D'Aprano
On Fri, 13 Jan 2012 11:04:48 -0800, Ethan Furman wrote: > With NaN, it is possible to get a list that will not properly sort: > > --> NaN = float('nan') > --> spam = [1, 2, NaN, 3, NaN, 4, 5, 7, NaN] --> sorted(spam) > [1, 2, nan, 3, nan, 4, 5, 7, nan] > > I'm constructing a Null object with the

Re: NaN, Null, and Sorting

2012-01-13 Thread MRAB
On 13/01/2012 19:58, Chris Angelico wrote: On Sat, Jan 14, 2012 at 6:04 AM, Ethan Furman wrote: So I am strongly leaning towards implementing the comparisons such that Null objects are less than other objects so they will always sort together. This is a perfectly plausible view, and is the

Re: NaN, Null, and Sorting

2012-01-13 Thread Chris Angelico
On Sat, Jan 14, 2012 at 6:04 AM, Ethan Furman wrote: > So I am strongly leaning towards implementing the comparisons such that Null > objects are less than other objects so they will always sort together. This is a perfectly plausible view, and is the one adopted by SQL (I'm pretty sure the "NULL

NaN, Null, and Sorting

2012-01-13 Thread Ethan Furman
With NaN, it is possible to get a list that will not properly sort: --> NaN = float('nan') --> spam = [1, 2, NaN, 3, NaN, 4, 5, 7, NaN] --> sorted(spam) [1, 2, nan, 3, nan, 4, 5, 7, nan] I'm constructing a Null object with the semantics that if the returned object is Null, it's actual value is