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

2019-12-29 Thread Steven D'Aprano
On Sun, Dec 29, 2019 at 08:32:52PM -0800, Andrew Barnert via Python-ideas wrote: > The 95% case is handled by just ignore and raise. Novices should > probably never be using anything else. > > Experts will definitely often want poison. And probably sometimes fast > for backward compatibility

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

2019-12-29 Thread Steven D'Aprano
On Sun, Dec 29, 2019 at 06:23:03PM -0800, Andrew Barnert via Python-ideas wrote: > Likewise, it’s even easier to write ignore-nan yourself than to write the DSU > yourself: > > median = statistics.median(x for x in xs if not x.isnan()) Try that with xs = [1, 10**400, 2] and come back to

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

2019-12-29 Thread Steven D'Aprano
On Sun, Dec 29, 2019 at 07:59:26PM -0500, Richard Damon wrote: > Which is EXACTLY the reason I say that if this is important enough to > fix in median, it is important enough to fix in sorted. sorted gives > exactly the same nonsense result, it is only a bit more obvious because > it gives all

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

2019-12-29 Thread Chris Angelico
On Mon, Dec 30, 2019 at 3:52 PM Andrew Barnert wrote: > > On Dec 29, 2019, at 18:50, Chris Angelico wrote: > > > > On Mon, Dec 30, 2019 at 1:40 PM Andrew Barnert wrote: > >> > >>> On Dec 29, 2019, at 18:20, Chris Angelico wrote: > >> > >> Counting numbers are intuitively numbers. So are

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

2019-12-29 Thread Steven D'Aprano
On Sun, Dec 29, 2019 at 06:22:49PM -0500, Richard Damon wrote: > The way I see it, is that median doesn't handle NaNs in a reasonable > way, because sorted doesn't handle them, because it is easy and quick to > not handle NaN, and to handle them you need to define an Official > meaning for

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

2019-12-29 Thread Tim Peters
[David Mertz] >> As me and Uncle Timmy have pointed out, it IS FIXED in sorted(). You just >> need to call: >> >>sorted_stuff = sorted(stuff, key=nan_aware_transform) [Christopher Barker] > But what would that be? floats have inf and -inf -- so how could you force > the NaNs to be at the

[Python-ideas] Re: Total_order

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 20:22, David Mertz wrote: > > Has anyone actually ever used those available bits for the zillions of NaNs > for anything good? Good? No. But I have used qNaN payloads for smuggling tagged values through a JS bridge or AppleEvents. It turns out that it’s a lot harder to

[Python-ideas] Re: Total_order

2019-12-29 Thread Tim Peters
[David] > What is it, 2**48-2 signaling NaNs and 2**48 quiet NaNs? Is my quick count > correct (in 64-bit)? Any bit pattern where the exponent is all ones (there are 11 exponent bits, giving 2**(64-11) = 2**53 bit patterns with an all-ones exponent), _and_ the significand isn't all 0 (it's an

[Python-ideas] Re: Total_order

2019-12-29 Thread Anders Hovmöller
> On 30 Dec 2019, at 05:55, Tim Peters wrote: > > [David] >> Has anyone actually ever used those available bits for the zillions of NaNs >> for >> anything good? > > Yes: in Python, many sample programs I've posted cleverly use NaN > bits to hide ASCII encodings of delightful puns ;-) > >

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

2019-12-29 Thread Christopher Barker
On Sun, Dec 29, 2019 at 5:14 PM David Mertz wrote: > As me and Uncle Timmy have pointed out, it IS FIXED in sorted(). You just > need to call: > >sorted_stuff = sorted(stuff, key=nan_aware_transform) > But what would that be? floats have inf and -inf -- so how could you force the NaNs to

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

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 21:00, David Mertz wrote: > >  >> On Sun, Dec 29, 2019 at 11:33 PM Andrew Barnert wrote: > >> IEEE total order specifies a distinct order for every distinct bit pattern, >> and tries to do so in a way that makes sense. > > Ok, ok... I've got "learned up" about this three

[Python-ideas] Re: Total_order

2019-12-29 Thread David Mertz
What is it, 2**48-2 signaling NaNs and 2**48 quiet NaNs? Is my quick count correct (in 64-bit)? Great opportunity for steganography, I reckon. On Sun, Dec 29, 2019 at 11:51 PM Tim Peters wrote: > [David] > > Has anyone actually ever used those available bits for the zillions of > NaNs for > >

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

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 20:04, Richard Damon wrote: > > Thus your total_order, while not REALLY a total order, is likely good enough > for most purposes. Well, it is a total order of equivalence classes (with all IEEE-equal values being equivalent, all negative NaNs being equivalent, and all

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

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019 at 11:33 PM Andrew Barnert wrote: > IEEE total order specifies a distinct order for every distinct bit > pattern, and tries to do so in a way that makes sense. > Ok, ok... I've got "learned up" about this three times now :-). Given we cannot control those bit patterns from

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

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 18:50, Chris Angelico wrote: > > On Mon, Dec 30, 2019 at 1:40 PM Andrew Barnert wrote: >> >>> On Dec 29, 2019, at 18:20, Chris Angelico wrote: >> >> Counting numbers are intuitively numbers. So are measures. And yet, they’re >> different. Which one is the “one true

[Python-ideas] Total_order

2019-12-29 Thread David Mertz
In the IEEE total order, +0 and -0 are distinct, which your order doesn't handle, For NaNs, the issue is that NaN is NOT a single representation, but each combination of the sign bit and the 52 mantissa bits (except all zeros which signify infinity) when the exponent field is all ones is a

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

2019-12-29 Thread Tim Peters
[David] > How is that fancy bitmask version different from my 3-line version? Where he's referring to my: https://bugs.python.org/msg336487 and, I presume, to his: def total_order(x): if math.isnan(x): return (math.copysign(1, x), x) . return (0, x) \ Richard

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

2019-12-29 Thread Richard Damon
On 12/29/19 11:00 PM, Tim Peters wrote: [Richard Damon ] IEEE total_order puts NaN as bigger than infinity, and -NaN as less than -inf. One simple way to implement it is to convert the representaton to a 64 bit signed integer (not its value, but its representation) and if the sign bit is set,

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

2019-12-29 Thread David Mertz
How is that fancy bitmask version different from my 3-line version? On Sun, Dec 29, 2019, 11:01 PM Tim Peters wrote: > [Richard Damon ] > > IEEE total_order puts NaN as bigger than infinity, and -NaN as less than > > -inf. > > > > One simple way to implement it is to convert the representaton

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

2019-12-29 Thread Richard Damon
On 12/29/19 10:39 PM, David Mertz wrote: On Sun, Dec 29, 2019 at 10:18 PM Richard Damon mailto:rich...@damon-family.org>> wrote: IEEE total_order puts NaN as bigger than infinity, and -NaN as less than -inf. You mean like this? >>> def total_order(x): ...     if math.isnan(x): ...    

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

2019-12-29 Thread Tim Peters
[Richard Damon ] > IEEE total_order puts NaN as bigger than infinity, and -NaN as less than > -inf. > > One simple way to implement it is to convert the representaton to a 64 > bit signed integer (not its value, but its representation) and if the > sign bit is set, complement the bottom 63 bits

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

2019-12-29 Thread Richard Damon
On 12/29/19 9:46 PM, Chris Angelico wrote: On Mon, Dec 30, 2019 at 1:40 PM Andrew Barnert wrote: On Dec 29, 2019, at 18:20, Chris Angelico wrote: On Mon, Dec 30, 2019 at 11:47 AM Steven D'Aprano wrote: On Mon, Dec 30, 2019 at 08:30:41AM +1100, Chris Angelico wrote: Especially since it

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

2019-12-29 Thread Steven D'Aprano
On Sun, Dec 29, 2019 at 05:40:09PM -0800, Neil Girdhar wrote: > I'm just glancing at this thread, but it sounds like you want to add the > quickselect algorithm to the standard library. As you point out in > another message, quickselect is faster than quicksort: it is linear time > (provided

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

2019-12-29 Thread Richard Damon
On 12/29/19 9:42 PM, David Mertz wrote: On Sun, Dec 29, 2019, 9:23 PM Andrew Barnert Here it is. I could save a line by not using the 'else'. def total_order(x):     if is_nan(x):     return (math.copysign(1, x), x)     else:     return (0, x) This

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

2019-12-29 Thread Steven D'Aprano
On Sun, Dec 29, 2019 at 07:43:28PM -0500, David Mertz wrote: > the notional approximations that bit-patterns give of Rational numbers (not > sure why Richard keeps insisting it's about Reals, not Rationals... albeit > there is no difference that means anything to this discussion). Excluding NANs

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

2019-12-29 Thread David Mertz
"*Die ganzen Zahlen hat der liebe Gott gemacht, alles andere ist Menschenwerk*" ("God made the integers, all else is the work of man"). –Leopold Kronecker of course, Kronecker was wrong, and Cantor was right. But the quote is an excellent dis. :-) On Sun, Dec 29, 2019 at 9:41 PM Andrew

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

2019-12-29 Thread Chris Angelico
On Mon, Dec 30, 2019 at 1:40 PM Andrew Barnert wrote: > > On Dec 29, 2019, at 18:20, Chris Angelico wrote: > > > > On Mon, Dec 30, 2019 at 11:47 AM Steven D'Aprano > > wrote: > >> > >> On Mon, Dec 30, 2019 at 08:30:41AM +1100, Chris Angelico wrote: > >> > Especially since it fails quite

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

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019, 9:23 PM Andrew Barnert > Here it is. I could save a line by not using the 'else'. > > def total_order(x): > if is_nan(x): > return (math.copysign(1, x), x) > else: > return (0, x) > > > This doesn’t give you IEEE total order. Under what circumstances

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

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 18:20, Chris Angelico wrote: > > On Mon, Dec 30, 2019 at 11:47 AM Steven D'Aprano wrote: >> >> On Mon, Dec 30, 2019 at 08:30:41AM +1100, Chris Angelico wrote: >> Especially since it fails quite a few commonsense tests for whether or not something is a number: >>

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

2019-12-29 Thread Steven D'Aprano
On Sat, Dec 28, 2019 at 10:16:28PM -0800, Christopher Barker wrote: > Richard: I am honestly confused about what you think we should do. Sure, > you can justify why the statistics module doesn’t currently handle NaN’s > well, but that doesn’t address the question of what it should do. > > As far

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

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 17:30, David Mertz wrote: > >  >> On Sun, Dec 29, 2019 at 8:14 PM Andrew Barnert wrote: >> On Dec 29, 2019, at 16:08, David Mertz wrote: >> > >> > * There is absolutely no need to lose any efficiency by making the >> > statistics functions more friendly. All we need is

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

2019-12-29 Thread Chris Angelico
On Mon, Dec 30, 2019 at 11:47 AM Steven D'Aprano wrote: > > On Mon, Dec 30, 2019 at 08:30:41AM +1100, Chris Angelico wrote: > > > > Especially since it fails quite a few commonsense tests for whether or > > > not something is a number: > [...] > > > The answer in all four cases is No. If

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

2019-12-29 Thread David Mertz
Actually, I wouldn't mind passing a key function to _median(), but that is way too advanced for the beginner users to have to think about. So maybe median() could call _median() internally where needed, but the underscore version could exist also. On Sun, Dec 29, 2019 at 8:14 PM Andrew Barnert

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

2019-12-29 Thread Neil Girdhar
I'm just glancing at this thread, but it sounds like you want to add the quickselect algorithm to the standard library. As you point out in another message, quickselect is faster than quicksort: it is linear time (provided the pivot is chosen by median of medians) whereas quicksort is

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

2019-12-29 Thread David Mertz
median() does not currently take a key function. This is not hard to see. It could, but as I've written, I don't think that's the best approach. In [16]: statistics.median?? Signature: statistics.median(data) Source: def median(data): """Return the median (middle value) of numeric data.

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

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019 at 8:14 PM Andrew Barnert wrote: > On Dec 29, 2019, at 16:08, David Mertz wrote: > > > > * There is absolutely no need to lose any efficiency by making the > statistics functions more friendly. All we need is an optional parameter > whose spelling I've suggested as

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

2019-12-29 Thread Richard Damon
On 12/29/19 8:13 PM, David Mertz wrote: On Sun, Dec 29, 2019 at 8:00 PM Richard Damon mailto:rich...@damon-family.org>> wrote: Which is EXACTLY the reason I say that if this is important enough to fix in median, it is important enough to fix in sorted. sorted gives exactly the same

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

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 16:08, David Mertz wrote: > > * There is absolutely no need to lose any efficiency by making the statistics > functions more friendly. All we need is an optional parameter whose spelling > I've suggested as `on_nan` (but bikeshed freely). Under at least one value > of

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

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019 at 8:00 PM Richard Damon wrote: > Which is EXACTLY the reason I say that if this is important enough to > fix in median, it is important enough to fix in sorted. sorted gives > exactly the same nonsense result, it is only a bit more obvious because > it gives all the points.

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

2019-12-29 Thread Richard Damon
On 12/29/19 7:43 PM, Tim Peters wrote: [Christopher Barker ] ... But the biggest barrier is that it would be a fair bit of churn on the sort() functions (and the float class), and would only help for floats anyway. If someone want to propose this, please do -- but I don't think we should wait

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

2019-12-29 Thread David Mertz
Oh... I made a mistake in my off-the-cuff code. The items.append() shouldn't be in an else, but just in the loop. def median(it, on_nan=DEFAULT): if on_nan == 'unsafe': ... do all the current stuff ... elif on_nan == "ignore": return median((x for x in it if not is_nan(x)),

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

2019-12-29 Thread Richard Damon
On 12/29/19 7:05 PM, Christopher Barker wrote: On Sun, Dec 29, 2019 at 3:26 PM Richard Damon mailto:rich...@damon-family.org>> wrote: > Frankly, I’m also confused as to why folks seem to think this is an > issue to be addressed in the sort() functions The way I see it, is that

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

2019-12-29 Thread Christopher Barker
Thanks David for laying a proposal out clearly: +1 to the whole thing. -CHB On Sun, Dec 29, 2019 at 4:06 PM David Mertz wrote: > Several points: > > * NaN as missing-value is widely used outside the Python standard > library. One could argue, somewhat reasonably, that Pandas and NumPy and >

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

2019-12-29 Thread Christopher Barker
Sorry for all these posts, but maybe someone mentioned this already, but maybe this is a time to consider a new algorithm anyway: https://rcoh.me/posts/linear-time-median-finding/ And doing the NaN-check inline might be faster than pre-filtering. -CHB On Sun, Dec 29, 2019 at 4:39 PM

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

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019 at 7:35 PM Andrew Barnert wrote: > On Dec 29, 2019, at 15:19, David Mertz wrote:On Sun, > Dec 29, 2019, 5:20 PM Andrew Barnert via Python-ideas > > But it is, out of all of the possible magma-over-magma structures on those >> values, the one that most closely

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

2019-12-29 Thread Tim Peters
[Christopher Barker ] > ... > But the biggest barrier is that it would be a fair bit of churn on the sort() > functions > (and the float class), and would only help for floats anyway. If someone want > to propose this, please do -- but I don't think we should wait for that to do > something >

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

2019-12-29 Thread Steven D'Aprano
On Mon, Dec 30, 2019 at 08:30:41AM +1100, Chris Angelico wrote: > > Especially since it fails quite a few commonsense tests for whether or > > not something is a number: [...] > > The answer in all four cases is No. If something doesn't quack like a > > duck, doesn't swim like a duck, and doesn't

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

2019-12-29 Thread Christopher Barker
On Sun, Dec 29, 2019 at 4:05 PM Christopher Barker wrote: > >> You mean performance? Sure, but as I've argued before (no idea if anyone > agrees with me) the statistics package is already not a high performance > package anyway. If it turns out that it slows it down by, say, a factor of > two or

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

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 15:19, David Mertz wrote: > >  > On Sun, Dec 29, 2019, 5:20 PM Andrew Barnert via Python-ideas >> But it is, out of all of the possible magma-over-magma structures on those >> values, the one that most closely approximates—in a well-defined and useful, >> if very

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

2019-12-29 Thread Richard Damon
On 12/29/19 5:41 PM, Chris Angelico wrote: On Mon, Dec 30, 2019 at 9:01 AM Richard Damon wrote: On 12/29/19 4:30 PM, Chris Angelico wrote: On Mon, Dec 30, 2019 at 5:48 AM Steven D'Aprano wrote: On Sat, Dec 28, 2019 at 09:20:49PM -0800, Brendan Barnwell wrote: Especially since it fails

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

2019-12-29 Thread David Mertz
Several points: * NaN as missing-value is widely used outside the Python standard library. One could argue, somewhat reasonably, that Pandas and NumPy and PyTorch misinterpret the IEEE-754 intention here, but this is EVERYWHERE in numeric/scientific Python. We could DOCUMENT that None is a

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

2019-12-29 Thread Christopher Barker
On Sun, Dec 29, 2019 at 3:26 PM Richard Damon wrote: > > Frankly, I’m also confused as to why folks seem to think this is an > > issue to be addressed in the sort() functions > > The way I see it, is that median doesn't handle NaNs in a reasonable > way, because sorted doesn't handle them, I

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

2019-12-29 Thread Richard Damon
On 12/29/19 1:16 AM, Christopher Barker wrote: OMG! Thus is fun and all, but: On Sat, Dec 28, 2019 at 9:11 PM Richard Damon mailto:rich...@damon-family.org>> wrote: ... practicality beats purity. And practically, everyone in this thread understands what a float is, and what a NaN is

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

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019, 5:20 PM Andrew Barnert via Python-ideas > But it is, out of all of the possible magma-over-magma structures on those > values, the one that most closely approximates—in a well-defined and > useful, if very complicated, way—the rationals. I'm sort of convinced that Posits

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

2019-12-29 Thread Chris Angelico
On Mon, Dec 30, 2019 at 9:01 AM Richard Damon wrote: > > On 12/29/19 4:30 PM, Chris Angelico wrote: > > On Mon, Dec 30, 2019 at 5:48 AM Steven D'Aprano wrote: > >> On Sat, Dec 28, 2019 at 09:20:49PM -0800, Brendan Barnwell wrote: > >> > >> Especially since it fails quite a few commonsense tests

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

2019-12-29 Thread Greg Ewing
On 30/12/19 3:47 am, Steven D'Aprano wrote: I'd like to understand the use-case here. I guess it is "signalling NANs are an error, quiet NANs are missing data". Am I right? I'm having trouble seeing what signalling NaNs are useful for in general. If something has gone badly enough wrong that

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

2019-12-29 Thread Christopher Barker
OMG! Thus is fun and all, but: On Sat, Dec 28, 2019 at 9:11 PM Richard Damon wrote: > > ... practicality beats purity. And practically, everyone in this thread understands what a float is, and what a NaN is and is not. Richard: I am honestly confused about what you think we should do. Sure,

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

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 13:33, Chris Angelico wrote: > > More useful would be to look at the useful operations and invariants > that can be maintained, but that doesn't work too well for finite > subsets of numbers. Very few operations are closed for, say, "sixteen > bit integers". Nor for "rational

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

2019-12-29 Thread Richard Damon
On 12/29/19 4:30 PM, Chris Angelico wrote: On Mon, Dec 30, 2019 at 5:48 AM Steven D'Aprano wrote: On Sat, Dec 28, 2019 at 09:20:49PM -0800, Brendan Barnwell wrote: The things that computers work with are floats, and NaN is a float, so in any relevant sense it is a number; it is an instance

[Python-ideas] Re: The "When" Keyword

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 12:52, Richard Damon wrote: > > On 12/29/19 3:13 PM, Andrew Barnert via Python-ideas wrote: >>> On Dec 29, 2019, at 10:57, Abdur-Rahmaan Janhangeer >>> wrote: >>> On Sun, Dec 29, 2019 at 10:45 PM Antoine Rozo >>> > wrote: >>> >>>If

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

2019-12-29 Thread Chris Angelico
On Mon, Dec 30, 2019 at 5:48 AM Steven D'Aprano wrote: > > On Sat, Dec 28, 2019 at 09:20:49PM -0800, Brendan Barnwell wrote: > > > The things that > > computers work with are floats, and NaN is a float, so in any relevant > > sense it is a number; it is an instance of a numerical type. > > You

[Python-ideas] Re: The "When" Keyword

2019-12-29 Thread Richard Damon
On 12/29/19 3:13 PM, Andrew Barnert via Python-ideas wrote: On Dec 29, 2019, at 10:57, Abdur-Rahmaan Janhangeer wrote: On Sun, Dec 29, 2019 at 10:45 PM Antoine Rozo > wrote: If I see a "when" keyword in a code, I will think that the body will be

[Python-ideas] Re: The "When" Keyword

2019-12-29 Thread Ned Batchelder
New keywords breaking code is why any proposal for a new keyword has to have a really strong justification. There has to be a large benefit to balance the implied cost of breaking code. Your proposal (if I understand it correctly) is that "when" would execute exactly like "if".  That is not a

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

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 29, 2019, at 04:34, Steven D'Aprano wrote: > > On Sat, Dec 28, 2019 at 11:58:35PM -0800, Andrew Barnert via Python-ideas > wrote: > >> No it won’t, unless you assume here that no possible non-numeric types >> could ever have non-self-equal values. Which isn’t true. > > Reflexivity of

[Python-ideas] Re: The "When" Keyword

2019-12-29 Thread Abdur-Rahmaan Janhangeer
Yours, Abdur-Rahmaan Janhangeer pythonmembers.club | github Mauritius On Sun, Dec 29, 2019 at 10:45 PM Antoine Rozo wrote: > If I see a "when" keyword in a code, I will think that > the body will be executed later, when the

[Python-ideas] Re: The "When" Keyword

2019-12-29 Thread Antoine Rozo
Hi, Adding a new keyword will break many code because "when" would be a new reserved word, and may currently be used as a variable name. Also, "when" is not an equivalent of "if", it has a time-related connotation. If I see a "when" keyword in a code, I will think that the body will be executed

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

2019-12-29 Thread Steven D'Aprano
On Sat, Dec 28, 2019 at 09:20:49PM -0800, Brendan Barnwell wrote: > The things that > computers work with are floats, and NaN is a float, so in any relevant > sense it is a number; it is an instance of a numerical type. You seem to be assuming that `x is an instance of type float (or

[Python-ideas] Re: The "When" Keyword

2019-12-29 Thread Abdur-Rahmaan Janhangeer
Adding a new keyword automatically assumes breaking code. Yours, Abdur-Rahmaan Janhangeer pythonmembers.club | github Mauritius On Sun, Dec 29, 2019 at 10:43 PM Nathan wrote: > This would break any code that uses “when” as

[Python-ideas] Re: The "When" Keyword

2019-12-29 Thread Nathan
This would break any code that uses “when” as a variable name. https://github.com/search?l=Python=when=Code On Sun, Dec 29, 2019 at 11:26 AM Abdur-Rahmaan Janhangeer < arj.pyt...@gmail.com> wrote: > Greetings list, > > I was wondering if adding the When keyword is a good idea. > Normally every

[Python-ideas] The "When" Keyword

2019-12-29 Thread Abdur-Rahmaan Janhangeer
Greetings list, I was wondering if adding the When keyword is a good idea. Normally every when is theoretically an if as you can't be sure if the event will 100% come to pass. if x == 5: ... else: ... However, we use the when keyword in normal language. When you reach home, phone me.

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

2019-12-29 Thread Richard Damon
On 12/29/19 10:58 AM, David Mertz wrote: On Sun, Dec 29, 2019, 10:51 AM Steve Barnes > wrote: I  do have to disagree here as it is entirely possible, in the world of hardware interfacing, that an external hardware device could possibly supply an sNaN 

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

2019-12-29 Thread Steve Barnes
From: David Mertz Sent: 29 December 2019 15:58 To: Steve Barnes Cc: Steven D'Aprano ; python-ideas Subject: Re: [Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?] On Sun, Dec 29, 2019, 10:51 AM Steve Barnes mailto:gadgetst...@live.co.uk>> wrote: I do have to disagree

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

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019, 10:51 AM Steve Barnes wrote: > I do have to disagree here as it is entirely possible, in the world of > hardware interfacing, that an external hardware device could possibly > supply an sNaN as a something was seriously wrong flag, (as opposed to a I > haven't got any

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

2019-12-29 Thread Steve Barnes
From: Steven D'Aprano Sent: 29 December 2019 14:47 To: python-ideas@python.org Subject: [Python-ideas] Re: Testing for NANs [was Re: Fix statistics.median()?] On Sun, Dec 29, 2019 at 08:22:49AM -0500, David Mertz wrote: > Signalling NaN's are a pain because I'd want: > > is_nan(snan) == True >

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

2019-12-29 Thread David Mertz
On Sun, Dec 29, 2019, 9:50 AM Steven D'Aprano wrote: > On Sun, Dec 29, 2019 at 08:22:49AM -0500, David Mertz wrote: > > Signalling NaN's are a pain because I'd want: > > > > is_nan(snan) == True > > > > But statistics.median([1, 2, snan], on_nan='ignore') to raise an > exception. > > So you want

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

2019-12-29 Thread Mark Dickinson
Honestly, I don't think we should let the behaviour of signaling NaNs influence the design decisions much here, beyond that yes, `is_nan(some_decimal_snan)` should return `True` (and not raise). They hardly ever turn up in practice, and unlike regular NaNs, you're unlikely to encounter them by

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

2019-12-29 Thread Steven D'Aprano
On Sun, Dec 29, 2019 at 08:22:49AM -0500, David Mertz wrote: > Signalling NaN's are a pain because I'd want: > > is_nan(snan) == True > > But statistics.median([1, 2, snan], on_nan='ignore') to raise an exception. So you want to skip quiet NANs and raise on signalling NANs? I'd like to

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

2019-12-29 Thread Juancarlo Añez
All your observations are on the mark, Andrew, so I went ahead and coded the patch against *cpython*. This is the (draft) pull request. https://github.com/python/cpython/pull/17735 I did not write new tests for *findalliter() *or *findfirst()*, because the correctness of *findalliter()* is

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

2019-12-29 Thread Richard Damon
On 12/29/19 12:20 AM, Brendan Barnwell wrote: 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

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

2019-12-29 Thread David Mertz
Signalling NaN's are a pain because I'd want: is_nan(snan) == True But statistics.median([1, 2, snan], on_nan='ignore') to raise an exception. And I'd want: statistics.median([1, 2, 3, qnan], on_nan='ignore') == 2 So we're back to needing yet another function is_nonsignaling_nan(). On Sun,

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

2019-12-29 Thread Steven D'Aprano
On Sat, Dec 28, 2019 at 09:35:07PM -0800, Christopher Barker wrote: > 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

[Python-ideas] Re: AVG Function as Built-in

2019-12-29 Thread Steven D'Aprano
On Thu, Dec 26, 2019 at 05:51:09PM -, Marco Sulla via Python-ideas wrote: > Stephen J. Turnbull wrote: > > > from statistics import mean > > > sum([1e16,1,1])/3 == 1e16/3# surprise! > > > True > > > mean([1e16,1,1]) == 1e16/3 > > > False > > > Regards, > > Python 3.9.0a0

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

2019-12-29 Thread Christopher Barker
On Sat, Dec 28, 2019 at 11:29 PM Steve Barnes wrote: > > > How about something along the lines of: > > def isnan(num): > > """ Attempt at generic NaN check """ > > if hasattr(num, "is_nan"): # Does it have its own method? > > return num.is_nan() > > else: > >

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

2019-12-29 Thread Andrew Barnert via Python-ideas
On Dec 28, 2019, at 23:29, Steve Barnes wrote: > >  > 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,