On Sep 19, 2006, at 9:45 PM, Tim Hochberg wrote: > Perhaps there's some use for the sort to end behaviour that I'm > missing, > but the raise an exception behaviour sure looks a lot more > appealing to me.
FYI, in IDL the NaN values wind up at the end of the sorted array. That's true despite the fact that IDL does respect all the comparison properties of NaNs (i.e. Value>NaN, Value<NaN, and Value==NaN are all false for any value). So clearly the sort behavior was created deliberately. It's also the case that the median for arrays including NaN values is computed as the median of the defined values, ignoring the NaNs. My view is that if the user has NaN values in the array, sort should respect the float exception flags and should only raise an exception if that is what the user has requested. > Here's a strawman proposal: > > Sort the array. Then examine numpy.geterr()['invalid']. If it > is not > 'ignore', then check examine sometrue(isnan(thearray)). If the > latter is true then raise and error, issue a warning or call the > error reporting functioni as appropriate. Note that we always sort > the array to be consistent with the behaviour of the ufuncs that > proceed even when they end up raising an exception. Here's another proposal: Make a first pass through the array, replacing NaN values with Inf and counting the NaNs ("nancount"). Raise an exception at this point if NaNs are not supposed to be allowed. Otherwise sort the array, and then as the last step replace the trailing NaNcount values with NaN. It seems to me that this would give predictable results while respecting the exception flags at little extra cost. Rick ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion