[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-28 Thread Steve Barnes
From: Andrew Barnert Sent: 28 December 2019 20:21 To: Steve Barnes Cc: Christopher Barker ; gu...@python.org; python-ideas Subject: Re: [Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?] On Dec 28, 2019, at 00:03, Steve Barnes mailto:gadgetst...@live.co.uk>> wrote:  Per

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread Christopher Barker
On Sat, Dec 28, 2019 at 9:42 PM Brendan Barnwell wrote: >But that is the problem. "The applied mathematics of computing" is > floating point, and in floating point, NaN is a number (despite its > name). careful here -- that may just re-ignite the argument :-( > computers work with ar

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread David Mertz
On Sun, Dec 29, 2019, 12:14 AM Richard Damon wrote: > But practicality beats purity, and practically, bit pattern CAN > represent numbers. If you want to argue that floats are not numbers, than > we can't use the statistics package, as we can't have any numbers to > perform the statistics on. >

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread Brendan Barnwell
On 2019-12-28 21:11, Richard Damon wrote: You seem to understand Pure Math, but not the Applied Mathematics of computers. The Applied Mathematics of Computing is based on the concept of finite approximation, which is something that Pure Math, like the type that builds up the Number line starting

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-28 Thread Christopher Barker
On Sat, Dec 28, 2019 at 3:40 PM David Mertz wrote: > What about Decimal snan? > That version tries to call .is_nan() first, so works fine with the Decimal snan. But as Nark pointed out, having an s an raise maybe the right thing to do anyway— it should not be used to indicate a missing value an

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread Richard Damon
On 12/28/19 11:44 PM, David Mertz wrote: On Sat, Dec 28, 2019, 11:02 PM Chris Angelico > wrote: They really truly ARE numbers. They are, in fact, these numbers: a = 3602879701896397 / 36028797018963968 b = 3602879701896397 / 18014398509481984 c = 5404319

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread David Mertz
On Sat, Dec 28, 2019, 11:02 PM Chris Angelico wrote: > They really truly ARE numbers. They are, in fact, these numbers: > > a = 3602879701896397 / 36028797018963968 > b = 3602879701896397 / 18014398509481984 > c = 5404319552844595 / 18014398509481984 > > When you perform addition on these, the re

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread Richard Damon
On 12/28/19 10:41 PM, David Mertz wrote: On Sat, Dec 28, 2019 at 10:31 PM Richard Damon mailto:rich...@damon-family.org>> wrote: Every value of the type float, except NaN and perhaps +inf and -inf (depending on which version of the Real Number Line you use) IS actually a represe

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread Chris Angelico
On Sun, Dec 29, 2019 at 2:44 PM David Mertz wrote: > > On Sat, Dec 28, 2019 at 10:31 PM Richard Damon > wrote: >> >> Every value of the type float, except NaN and perhaps +inf and -inf >> (depending on which version of the Real Number Line you use) IS actually >> a representation of a Real Numbe

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread David Mertz
On Sat, Dec 28, 2019 at 10:31 PM Richard Damon wrote: > Every value of the type float, except NaN and perhaps +inf and -inf > (depending on which version of the Real Number Line you use) IS actually > a representation of a Real Number (so I don't understand in what way you > can say they aren't "

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread Richard Damon
On 12/28/19 10:05 PM, David Mertz wrote: On Sat, Dec 28, 2019, 9:36 PM Richard Damon > wrote: > NaN may be an instance of the abstract type Number, but is isn't a mathematical number. Yes, floating point numbers are not pure-math Reals. Not even Ration

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread David Mertz
On Sat, Dec 28, 2019, 9:36 PM Richard Damon wrote: > > NaN may be an instance of the abstract type Number, but is isn't a > mathematical number. Yes, floating point numbers are not pure-math Reals. Not even Rationals. They are a CS construct that is very useful for computer programs that very a

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread Ricky Teachey
An idea I haven't seen anyone suggest: Since testing for nan can be expensive, maybe it would make sense to provide a statistics.median_unsafe(), or perhaps median_fast(), method with the current implementation (for situations where a slow down isn't acceptable), and update the median() function t

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread Richard Damon
On 12/28/19 8:40 PM, David Mertz wrote: This is sophistry. NaN is an instance of the abstract type numbers.Number and the concrete type float. IEEE-754 defines NaN as collection of required values in any floating point type. I know the acronym suggests otherwise in a too-cute way, but NaN is

[Python-ideas] Re: Alternative to `enumerate` and `range(len(sequence))`: indexes() and entries()

2019-12-28 Thread Soni L.
You want Lua. and pairs(). I have my own pairs() implementation as part of my library. It handles the following: - Sequence becomes enumerate(seq) - Mapping becomes seq.items() - Set becomes ((x,x) for x in set) - Everything else is an error. (Arguably Set should be (x, None) or (x, True) or

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread David Mertz
This is sophistry. NaN is an instance of the abstract type numbers.Number and the concrete type float. IEEE-754 defines NaN as collection of required values in any floating point type. I know the acronym suggests otherwise in a too-cute way, but NaN is archetypically a number in a computer science

[Python-ideas] Re: Fix statistics.median()?

2019-12-28 Thread Richard Damon
On 12/28/19 1:14 AM, Christopher Barker wrote: On Fri, Dec 27, 2019 at 8:14 PM Richard Damon mailto:rich...@damon-family.org>> wrote: > It is a well known axiom of computing that returning an *incorrect* > result is a very bad thing. There is also an axiom that you can only expect

[Python-ideas] Re: findfirst() from findalliter(), and first

2019-12-28 Thread Random832
On Fri, Dec 27, 2019, at 11:58, Juancarlo Añez wrote: > Fon *first()*, maybe calling it *take_one()* will clear up > misunderstandings about it's semantics. It may be worth mentioning that take [arbitrary n] is already present in itertools recipes. Though that gets into the debates about what sh

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-28 Thread David Mertz
What about Decimal snan? On Sat, Dec 28, 2019, 5:53 PM Christopher Barker wrote: > On Sat, Dec 28, 2019 at 2:41 AM Antoine Pitrou > wrote: > >> +1 for a .is_nan() method on suitable types. That's the most natural >> and elegant solution, IMHO. Tricks like "x == x" are nice when you >> *know*

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-28 Thread Christopher Barker
On Sat, Dec 28, 2019 at 2:41 AM Antoine Pitrou wrote: > +1 for a .is_nan() method on suitable types. That's the most natural > and elegant solution, IMHO. Tricks like "x == x" are nice when you > *know* that x is a float or Decimal, but not in the general case. > agreed -- while it may work in

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-28 Thread Eric V. Smith
On 12/28/2019 5:39 AM, Antoine Pitrou wrote: On Fri, 27 Dec 2019 23:52:13 -0800 Christopher Barker wrote: On Fri, Dec 27, 2019 at 5:39 PM Guido van Rossum wrote: Is duck typing float or Decimal worth the bother? Barring that it could be done with some isinstance() checks (in the user code, n

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-28 Thread Andrew Barnert via Python-ideas
On Dec 28, 2019, at 00:03, Steve Barnes wrote: > >  > Personally I still like the fundamental: > > def is_nan(num): > “”” Test for NaN “”” > return num != num > > So simple! This is only fundamental for types where all and only NaN values are not self-equal. Is that guaranteed to b

[Python-ideas] Re: findfirst() from findalliter(), and first

2019-12-28 Thread Andrew Barnert via Python-ideas
> On Dec 28, 2019, at 10:12, Juancarlo Añez wrote: > As far as I understand it, my implementation of findalliter() matches the > semantics in the switch statement. There’s nothing outside the switch statement that converts PyNone values to empty strings, so whatever the difference is, it must b

[Python-ideas] Re: findfirst() from findalliter(), and first

2019-12-28 Thread Juancarlo Añez
Good point, Andrew! I missed including the unit tests I wrote. I will now, at the bottom. For reference, this is the implementation of *findall()*: static PyObject * _sre_SRE_Pattern_findall_impl(PatternObject *self, PyObject *string, Py_ssize_t pos, Py_ssize_t endp

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-28 Thread Antoine Pitrou
On Fri, 27 Dec 2019 23:52:13 -0800 Christopher Barker wrote: > On Fri, Dec 27, 2019 at 5:39 PM Guido van Rossum wrote: > > > Is duck typing float or Decimal worth the bother? Barring that it could be > > done with some isinstance() checks (in the user code, not in math.isnan()). > > > > well,

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-28 Thread Antoine Pitrou
On Sat, 28 Dec 2019 19:31:33 +1100 Chris Angelico wrote: > On Sat, Dec 28, 2019 at 7:03 PM Steve Barnes wrote: > > > > Personally I still like the fundamental: > > > > > > > > def is_nan(num): > > > > “”” Test for NaN “”” > > > > return num != num > > > > Which was in Steven's original

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-28 Thread Mark Dickinson
The failure of the `x == x` test for signaling NaNs may be a non-issue in practice, for a couple of reasons; one is that signaling NaNs are *supposed* to raise when you do almost anything at all with them. The other is that, unlike a quiet NaN, it's hard to imagine how anyone would ever get a si

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-28 Thread Christopher Barker
On Sat, Dec 28, 2019 at 12:35 AM Chris Angelico wrote: > On Sat, Dec 28, 2019 at 7:03 PM Steve Barnes > wrote: > > > > Personally I still like the fundamental: > > > > def is_nan(num): > > > > “”” Test for NaN “”” > > > > return num != num > > > > Which was in Steven's original post, and

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-28 Thread Chris Angelico
On Sat, Dec 28, 2019 at 7:03 PM Steve Barnes wrote: > > Personally I still like the fundamental: > > > > def is_nan(num): > > “”” Test for NaN “”” > > return num != num > Which was in Steven's original post, and which is dangerous because a signalling nan will bomb. There's no easy way to

[Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?]

2019-12-28 Thread Steve Barnes
Personally I still like the fundamental: def is_nan(num): “”” Test for NaN “”” return num != num So simple! From: Christopher Barker Sent: 28 December 2019 07:54 To: gu...@python.org Cc: python-ideas Subject: [Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?] opps,