[issue33084] statistics module: NaN handling in median, median_high an median_low

2021-08-27 Thread Steven D'Aprano
Steven D'Aprano added the comment: See thread on Python-Ideas. https://mail.python.org/archives/list/python-id...@python.org/thread/EDRF2NR4UOYMSKE64KDI2SWUMKPAJ3YM/ -- ___ Python tracker

[issue33084] statistics module: NaN handling in median, median_high an median_low

2021-08-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: [Steven] > Thoughts? 1) Document that results are undefined if a NaN is present in the data. 2) Add function to strip NaNs from the data: def remove_nans(iterable): "Remove float('NaN') and other objects not equal to themselves"

[issue33084] statistics module: NaN handling in median, median_high an median_low

2021-08-20 Thread Irit Katriel
-- nosy: +iritkatriel title: Computing median, median_high an median_low in statistics library -> statistics module: NaN handling in median, median_high an median_low versions: +Python 3.10, Python 3.11, Python 3.9 -Python 3.8 __

Re: NaN handling

2006-05-06 Thread Dan Bishop
Ivan Vinogradov wrote: snip NaNs are handled. Throwing an exception would be nice in regular Python (non-scipy). This works to catch NaN on OSX and Linux: # assuming x is a number if x+1==x or x!=x: #x is NaN x != x works, but: x = 1e100 x + 1 == x True --

Re: NaN handling

2006-05-06 Thread Alexander Schmolck
Robert Kern [EMAIL PROTECTED] writes: Ivan Vinogradov wrote: It doesn't seem to be here under OSX either (universal Python install). It's not enabled by default. In the source distribution, it is Modules/fpectlmodule.c . Since numpy seems to be working on a variety of

Re: NaN handling

2006-05-06 Thread Felipe Almeida Lessa
Em Sex, 2006-05-05 às 16:37 -0400, Ivan Vinogradov escreveu: This works to catch NaN on OSX and Linux: # assuming x is a number if x+1==x or x!=x: #x is NaN This works everywhere: nan = float('nan') . . . if x == nan: # x is not a number -- Felipe. --

Re: NaN handling

2006-05-06 Thread Alexander Schmolck
Felipe Almeida Lessa [EMAIL PROTECTED] writes: Em Sex, 2006-05-05 às 16:37 -0400, Ivan Vinogradov escreveu: This works to catch NaN on OSX and Linux: # assuming x is a number if x+1==x or x!=x: #x is NaN This works everywhere: nan = float('nan') . . . if x == nan:

Re: NaN handling

2006-05-06 Thread Terry Reedy
Felipe Almeida Lessa [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] This works everywhere: nan = float('nan') Not. nan = float('nan') Traceback (most recent call last): File pyshell#4, line 1, in -toplevel- nan = float('nan') ValueError: invalid literal for float(): nan

Re: NaN handling

2006-05-06 Thread Ryan Forsythe
Terry Reedy wrote: Felipe Almeida Lessa [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] This works everywhere: nan = float('nan') Not. nan = float('nan') Traceback (most recent call last): File pyshell#4, line 1, in -toplevel- nan = float('nan') ValueError:

Re: NaN handling

2006-05-06 Thread Terry Reedy
Ryan Forsythe [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Terry Reedy wrote: Felipe Almeida Lessa [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] This works everywhere: nan = float('nan') Not. nan = float('nan') Traceback (most recent call last): File

Re: NaN handling

2006-05-06 Thread Robert Kern
Felipe Almeida Lessa wrote: Em Sex, 2006-05-05 às 16:37 -0400, Ivan Vinogradov escreveu: This works to catch NaN on OSX and Linux: # assuming x is a number if x+1==x or x!=x: #x is NaN This works everywhere: nan = float('nan') Have you tried it on Windows? -- Robert Kern I have

Re: NaN handling

2006-05-06 Thread Robert Kern
Alexander Schmolck wrote: Robert Kern [EMAIL PROTECTED] writes: Ivan Vinogradov wrote: Since numpy seems to be working on a variety of platforms/hardware, how hard would it be to extract this functionality from it to add to Python proper? Harder than just enabling fpectl. Last thing I

Re: NaN handling

2006-05-06 Thread Grant Edwards
to be completely broken -- it's likely not disabled by default for no reason. Fair enough. If you want to go through numpy's code to rip out its floating point error handling, knock yourself out. It's not going to be trivial, though. It's heavily embedded in the ufunc machinery. Does numpy's NaN

Re: NaN handling

2006-05-06 Thread Grant Edwards
On 2006-05-06, Terry Reedy [EMAIL PROTECTED] wrote: That's Python 2.4.1 on Mac OS X. float(NaN) Traceback (most recent call last): File pyshell#5, line 1, in -toplevel- float(NaN) ValueError: invalid literal for float(): NaN As Tim Peters has said often enough, this sort of thing

Re: NaN handling

2006-05-06 Thread Robert Kern
numpy's NaN handling only work within numpy functions, or does it enable HW FP signals and then catch them for normal floating point operations that take place outside of numpy code? Just in numpy code, it seems. In [1]: import numpy i In [2]: import math In [3]: numpy.seterr(invalid='raise

Re: NaN handling

2006-05-05 Thread Ivan Vinogradov
snip NaNs are handled. Throwing an exception would be nice in regular Python (non-scipy). This works to catch NaN on OSX and Linux: # assuming x is a number if x+1==x or x!=x: #x is NaN But is expensive as a precautionary measure. Assert can be used for testing, if production code

Re: NaN handling

2006-05-05 Thread Grant Edwards
On 2006-05-05, Ivan Vinogradov [EMAIL PROTECTED] wrote: snip NaNs are handled. Throwing an exception would be nice in regular Python (non-scipy). That would break most of my Python programs (at least most of the ones in which I do floating point). My main problem with NaNs (and Infs) is

Re: NaN handling

2006-05-05 Thread Ivan Vinogradov
snip There are those of us that need NaNs in production code, so it would have to be something that could be configured. I find that in my programs the places where I need to do something exceptional with a NaN are very limited. The vast majority of the time, I need them to propagate

Re: NaN handling

2006-05-05 Thread Robert Kern
Ivan Vinogradov wrote: snip There are those of us that need NaNs in production code, so it would have to be something that could be configured. I find that in my programs the places where I need to do something exceptional with a NaN are very limited. The vast majority of the time, I need them

Re: NaN handling

2006-05-05 Thread Grant Edwards
On 2006-05-05, Ivan Vinogradov [EMAIL PROTECTED] wrote: snip There are those of us that need NaNs in production code, so it would have to be something that could be configured. I find that in my programs the places where I need to do something exceptional with a NaN are very limited. The

Re: NaN handling

2006-05-05 Thread Grant Edwards
On 2006-05-05, Robert Kern [EMAIL PROTECTED] wrote: Our programming expectations may differ, but an option to catch NaNs as an exception is a great idea. [...] Pure Python has a similar, but somewhat less flexible method, on UNIX platforms.

Re: NaN handling

2006-05-05 Thread Robert Kern
Grant Edwards wrote: On 2006-05-05, Robert Kern [EMAIL PROTECTED] wrote: Pure Python has a similar, but somewhat less flexible method, on UNIX platforms. http://docs.python.org/dev/lib/module-fpectl.html For which Unix platforms? It's not there under Linux: Python 2.4.2 (#1, Feb 14

Re: NaN handling

2006-05-05 Thread Ivan Vinogradov
On 5-May-06, at 6:45 PM, Grant Edwards wrote: On 2006-05-05, Robert Kern [EMAIL PROTECTED] wrote: Our programming expectations may differ, but an option to catch NaNs as an exception is a great idea. [...] Pure Python has a similar, but somewhat less flexible method, on UNIX

Re: NaN handling

2006-05-05 Thread Robert Kern
Ivan Vinogradov wrote: It doesn't seem to be here under OSX either (universal Python install). It's not enabled by default. In the source distribution, it is Modules/fpectlmodule.c . Since numpy seems to be working on a variety of platforms/hardware, how hard would it be to extract this

NaN handling

2006-05-03 Thread Andy McDonagh
Dear python experts, I am new to python and this site, so I apologize if this is off topic (i.e. is it a SciPy question?). I will try to demonstrate my problem below: #!/usr/local/bin/python from scipy import * from scipy.stats import *

Re: NaN handling

2006-05-03 Thread Robert Kern
Andy McDonagh wrote: Dear python experts, I am new to python and this site, so I apologize if this is off topic (i.e. is it a SciPy question?). I will try to demonstrate my problem below: #!/usr/local/bin/python from scipy import

Re: NaN handling

2006-05-03 Thread Grant Edwards
On 2006-05-03, Andy McDonagh [EMAIL PROTECTED] wrote: Dear python experts, I am new to python and this site, so I apologize if this is off topic (i.e. is it a SciPy question?). I will try to demonstrate my problem below: