Re: Can one output something other than 'nan' for not a number values?

2024-02-19 Thread dn via Python-list
On 20/02/24 01:04, Chris Green via Python-list wrote: dn wrote: On 18/02/24 09:53, Grant Edwards via Python-list wrote: On 2024-02-17, Cameron Simpson via Python-list wrote: On 16Feb2024 22:12, Chris Green wrote: I'm looking for a simple way to make NaN values output as something

Re: Can one output something other than 'nan' for not a number values?

2024-02-19 Thread dn via Python-list
On 20/02/24 05:58, Grant Edwards via Python-list wrote: Here's a demonstration of how to hook custom code into the f-string formatting engine. It's brilliantly depraved. https://stackoverflow.com/questions/55876683/hook-into-the-builtin-python-f-string-format-machinery From the above: Yo

Re: Can one output something other than 'nan' for not a number values?

2024-02-19 Thread Grant Edwards via Python-list
On 2024-02-19, Chris Green via Python-list wrote: > It's using f'{...}' at the moment. Here's a demonstration of how to hook custom code into the f-string formatting engine. It's brilliantly depraved. https://stackoverflow.com/questions/55876683/hook-into-the-builtin-python-f-string-format-mach

Re: Can one output something other than 'nan' for not a number values?

2024-02-19 Thread Chris Green via Python-list
Grant Edwards wrote: > On 2024-02-16, Chris Green via Python-list wrote: > > > I'm looking for a simple way to make NaN values output as something > > like '-' or even just a space instead of the string 'nan'. > > It would probably help if yo

Re: Can one output something other than 'nan' for not a number values?

2024-02-19 Thread Chris Green via Python-list
dn wrote: > On 18/02/24 09:53, Grant Edwards via Python-list wrote: > > On 2024-02-17, Cameron Simpson via Python-list > > wrote: > >> On 16Feb2024 22:12, Chris Green wrote: > >>> I'm looking for a simple way to make NaN values output as something >

Re: Can one output something other than 'nan' for not a number values?

2024-02-18 Thread dn via Python-list
On 18/02/24 09:53, Grant Edwards via Python-list wrote: On 2024-02-17, Cameron Simpson via Python-list wrote: On 16Feb2024 22:12, Chris Green wrote: I'm looking for a simple way to make NaN values output as something like '-' or even just a space instead of

Re: Can one output something other than 'nan' for not a number values?

2024-02-18 Thread Chris Angelico via Python-list
On Mon, 19 Feb 2024 at 06:47, Grant Edwards via Python-list wrote: > I would be tempted to try monkey-patching the float class to override > the __format__ method. I have no idea what side effects that might > have, or if it's even used by the various formatting mechanisms, so > you might end up s

Re: Can one output something other than 'nan' for not a number values?

2024-02-18 Thread Piergiorgio Sartor via Python-list
On 16/02/2024 23.12, Chris Green wrote: I'm looking for a simple way to make NaN values output as something like '-' or even just a space instead of the string 'nan'. This would then make it much easier to handle outputting values from sensors when not all sensors are

Re: Can one output something other than 'nan' for not a number values?

2024-02-18 Thread Grant Edwards via Python-list
On 2024-02-16, Chris Green wrote: > I'm looking for a simple way to make NaN values output as something > like '-' or even just a space instead of the string 'nan'. I tried monkey-patching the __format__ method of float, but it's immutable, so that didnt

Can one output something other than 'nan' for not a number values?

2024-02-18 Thread Grant Edwards via Python-list
[I've been trying all afternoon to post via slrn, but nothing is showing up on the list. Forgive me if multiple posts eventually show up.] On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make N

Can one output something other than 'nan' for not a number values?

2024-02-18 Thread Grant Edwards via Python-list
[Posts via slrn and my GMail account aren't showing up, so I guess I'll try subscribing from a different e-mail address.] On 2024-02-17, Cameron Simpson via Python-list wrote: On 16Feb2024 22:12, Chris Green wrote: I'm looking for a simple way to make NaN values output as

Re: Can one output something other than 'nan' for not a number values?

2024-02-18 Thread Grant Edwards via Python-list
On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. [...] >> >>

Re: Can one output something other than 'nan' for not a number values?

2024-02-18 Thread Grant Edwards via Python-list
On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. [...] >> >>

Re: Can one output something other than 'nan' for not a number values?

2024-02-18 Thread Grant Edwards via Python-list
On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. [...] >> >>

Re: Can one output something other than 'nan' for not a number values?

2024-02-18 Thread Grant Edwards via Python-list
On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. >>[...] >> >&

Re: Can one output something other than 'nan' for not a number values?

2024-02-18 Thread Grant Edwards via Python-list
On 2024-02-16, Chris Green via Python-list wrote: > I'm looking for a simple way to make NaN values output as something > like '-' or even just a space instead of the string 'nan'. It would probably help if you told us how you're "outputting" them

Re: Can one output something other than 'nan' for not a number values?

2024-02-16 Thread Cameron Simpson via Python-list
On 16Feb2024 22:12, Chris Green wrote: I'm looking for a simple way to make NaN values output as something like '-' or even just a space instead of the string 'nan'. This would then make it much easier to handle outputting values from sensors when not all sensors are

Can one output something other than 'nan' for not a number values?

2024-02-16 Thread Chris Green via Python-list
I'm looking for a simple way to make NaN values output as something like '-' or even just a space instead of the string 'nan'. This would then make it much easier to handle outputting values from sensors when not all sensors are present. So, for example, my battery m

Re: naN values

2020-05-04 Thread Peter Otten
J Conrado wrote: > I have a 2d array and I would how can I replace NaN values for example > with - value or other value. >>> a array([[ nan, 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., nan]]) >>> a[numpy.isnan(a)] = 42 >>>

naN values

2020-05-04 Thread J Conrado
Hi, I have a 2d array and I would  how can I replace NaN values for example with - value or other value. Thank, Conrado -- https://mail.python.org/mailman/listinfo/python-list

chi square test in sklearn printing NAN values for most of the columns

2020-04-27 Thread Rahul Gupta
Hi i am trying to use chi-square Test to select most important columns among 5501 columns. But for most of the columns i am getting NAN value as a Chi test value import pandas as pd from sklearn.preprocessing import LabelEncoder from sklearn.feature_selection import chi2 cols =[] cols.append

RE: FW: Why float('Nan') == float('Nan') is False

2019-02-15 Thread Avi Gross
Greg, Good eye. You are correct! Yes, that is a side effect I did not intend when I cut and paste and the darn spell-checker saw it as useful to make my code act like the start of a normal text sentence. I just replicated it: >>> float(" nan") Nan As I watched, "nan&qu

Re: FW: Why float('Nan') == float('Nan') is False

2019-02-15 Thread Gregory Ewing
Avi Gross wrote: I can see why you may be wondering. You see the nan concept as having a specific spelling using all lowercase and to an extent you are right. No, he's talking about this particular line from the transcript you posted: >>>float(" nan") >

Re: FW: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Chris Angelico
On Fri, Feb 15, 2019 at 4:15 PM Avi Gross wrote: > > > You shouldn't be testing floats for identity. > > I am not suggesting anyone compare floats. I repeat that a nan is not > anything. Now as a technicality, it is considered a float by the type > command as there is

RE: FW: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Avi Gross
Chris, I don't wish to continue belaboring this topic but will answer you and then ignore anything non-essential. You said: > You shouldn't be testing floats for identity. I am not suggesting anyone compare floats. I repeat that a nan is not anything. Now as a technicality, it is

Re: FW: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Chris Angelico
On Fri, Feb 15, 2019 at 2:37 PM Avi Gross wrote: > But here is a curiosity. The numpy add-on package has a nan that is UNIQUE > so two copies are the same. Read this transcript and see if it might > sometimes even be useful while perhaps confusing the heck out of people who > assume

RE: FW: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Avi Gross
Grant, I can see why you may be wondering. You see the nan concept as having a specific spelling using all lowercase and to an extent you are right. As I pointed out. In the context of a string to convert to a float, any upper/lower-case spelling of NaN is accepted. But, to answer you anyway, I

Re: FW: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Grant Edwards
On 2019-02-14, Avi Gross wrote: > I experimented a bit: > >>>> float("nan ") > nan >>>> float(" nan") > Nan >>>> float(" nAn") > nan That's curious. I've never seen "Nan" before. What versi

FW: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Avi Gross
Other people have replied well enough with better ways to do this but I am stuck on WHY this was seen as a way to do this at all. The code was: r = float('Nan') while r==float('Nan'): inp = input("Enter a number\n") try: r = float(inp)

Re: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Joe Pfeiffer
Chris Angelico writes: > > Or even better, use None instead of nan. There's nothing in Python > says you have to (ab)use a floating-point value as a signal. Or use > "while True" and add a break if the exception isn't thrown. Good point. -- https://mail.python.org/mailman/listinfo/python-list

Re: Why float('Nan') == float('Nan') is False

2019-02-14 Thread אורי
> Or even better, use None instead of nan. ++ On Thu, Feb 14, 2019 at 3:26 AM Joe Pfeiffer wrote: > u...@speedy.net writes: > > > There are more integers than odd numbers, and more odd numbers than prime > > numbers. An infinite set may be a subset of another infinite set

Re: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Chris Angelico
On Fri, Feb 15, 2019 at 3:56 AM Joe Pfeiffer wrote: > > ast writes: > > > Le 13/02/2019 à 14:21, ast a écrit : > >> Hello > >> > >> >>> float('Nan') == float('Nan') > >> False > >> > >> Why ? >

Re: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Joe Pfeiffer
ast writes: > Le 13/02/2019 à 14:21, ast a écrit : >> Hello >> >> >>> float('Nan') == float('Nan') >> False >> >> Why ? >> >> Regards >> > > Thank you for answers. > > If you wonder how I

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread ast
Le 13/02/2019 à 14:21, ast a écrit : Hello >>> float('Nan') == float('Nan') False Why ? Regards Thank you for answers. If you wonder how I was trapped with it, here is the failing program. r = float('Nan') while r==float('Nan'): i

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Joe Pfeiffer
u...@speedy.net writes: > There are more integers than odd numbers, and more odd numbers than prime > numbers. An infinite set may be a subset of another infinite set although > they may both have the same cardinality. Or in other words, the number of > elements in each set is not equal. One has m

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Joe Pfeiffer
songbird writes: > Chris Angelico wrote: >> On Thu, Feb 14, 2019 at 7:12 AM Test Bot wrote: >>> >>> This definition of NaN is much better in mentally visualizing all the so >>> called bizarreness of IEEE. This also makes intuitive that no 2 NaN will be >&g

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Chris Angelico
On Thu, Feb 14, 2019 at 11:01 AM songbird wrote: > all such proofs i have ever seen are based upon the > assumptions that there are infinite numbers of such > things like primes. I posted an abbreviated proof of that in a footnote. It's a proof by contradiction. First, assume that there are, in

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread songbird
Chris Angelico wrote: > On Thu, Feb 14, 2019 at 7:12 AM Test Bot wrote: >> >> This definition of NaN is much better in mentally visualizing all the so >> called bizarreness of IEEE. This also makes intuitive that no 2 NaN will be >> equal just as no 2 infinities wou

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Chris Angelico
On Thu, Feb 14, 2019 at 9:07 AM Avi Gross wrote: > But that means that normal mathematics is warped. Well yes. Yes, it is. That's why people think "Alice's Adventures in Wonderland" is the result of a drug-induced dream - in actual fact, it's the result of the Dean of Mathematics telling stor

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Avi Gross
I think we should realize that Nan and NA and so on are human constructs people Define in programming languages. Some have subdivisions as in not an int as compared to not a float. Python also has an Inf as well as a -Inf that are abstractions and not a real, so to speak. Number. Mathematics

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Chris Angelico
‪On Thu, Feb 14, 2019 at 8:24 AM ‫אורי‬‎ wrote:‬ > On Wed, Feb 13, 2019 at 10:20 PM Chris Angelico wrote: >> >> Why would no two infinities be equal? In mathematics, there's one >> best-known infinity (aleph null, aka the number of counting numbers), >> and many many infinities are provably equal

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread אורי
אורי u...@speedy.net On Wed, Feb 13, 2019 at 10:20 PM Chris Angelico wrote: > On Thu, Feb 14, 2019 at 7:12 AM Test Bot wrote: > > > > This definition of NaN is much better in mentally visualizing all the so > > called bizarreness of IEEE. This also makes intuitive th

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Rob Gaddi
On 2/13/19 12:32 PM, Marko Rauhamaa wrote: "Avi Gross" : A NaN is a bit like a black hole. Anything thrown in disappears and that is about all we know about it. No two black holes are the same even if they seem to have the same mass, spin and charge. All they share is that we don&#

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Marko Rauhamaa
"Avi Gross" : > A NaN is a bit like a black hole. Anything thrown in disappears and > that is about all we know about it. No two black holes are the same > even if they seem to have the same mass, spin and charge. All they > share is that we don't know what is in them

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Chris Angelico
On Thu, Feb 14, 2019 at 7:12 AM Test Bot wrote: > > This definition of NaN is much better in mentally visualizing all the so > called bizarreness of IEEE. This also makes intuitive that no 2 NaN will be > equal just as no 2 infinities would be equal. I believe in a hypothesis(of >

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Test Bot
This definition of NaN is much better in mentally visualizing all the so called bizarreness of IEEE. This also makes intuitive that no 2 NaN will be equal just as no 2 infinities would be equal. I believe in a hypothesis(of my own creation) that any arithmetic on a data type of NaN would be

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Dan Sommers
On 2/13/19 1:53 PM, Grant Edwards wrote: Floating point is sort of the quantum mechanics of computer science. At first glance, it seems sort of weird. But after you work with it a while, it gets even worse. Yep! :-) -- https://mail.python.org/mailman/listinfo/python-list

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Chris Angelico
On Thu, Feb 14, 2019 at 6:55 AM Grant Edwards wrote: > > On 2019-02-13, Schachner, Joseph wrote: > > > This makes some sense because NAN is Not A Number, so any comparison > > to a number fails. > > Ah, but you now seem to be conflating "comparison fails" w

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Chris Angelico
On Thu, Feb 14, 2019 at 6:40 AM Schachner, Joseph wrote: > > Because all comparisons with NAN return false, that's the spec. Apart from !=, because it would be insane (I mean, even more insane than it is) to have nan == nan be false AND nan != nan. IEEE NAN has several purposes

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Grant Edwards
On 2019-02-13, Schachner, Joseph wrote: > This makes some sense because NAN is Not A Number, so any comparison > to a number fails. Ah, but you now seem to be conflating "comparison fails" with "comparison has a boolean value of False". The alternative to (nan == nan

RE: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Schachner, Joseph
Because all comparisons with NAN return false, that's the spec. is NAN > 0? False. Is NAN< 0? False. Is NAN == 0? False. Is NAN == ? False. So: Is NAN == NAN? False. And one more: Is NAN < 1.0e18? False This makes some sense because NAN is Not A Number, so any compariso

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Joe Pfeiffer
ast writes: > Hello > >>>> float('Nan') == float('Nan') > False > > Why ? > > Regards Others have given the real answer -- IEEE says so, and the people who wrote the standard are smarter than me. All the same, this is my take on the rea

RE: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Avi Gross
I won't speak for the IEEE but NOT A NUMBER does not tell you what something IS. If "Hello, World!" is not a number as in an int or a float and we throw away the content and simply call it a NaN or something and then we notice that an object that is a list of fruits is also not

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Grant Edwards
On 2019-02-13, ast wrote: > Hello > > >>> float('Nan') == float('Nan') > False If you think that's odd, how about this? >>> n = float('nan') >>> n nan >>> n is n True >>> n ==

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Dan Sommers
On 2/13/19 7:21 AM, ast wrote: Hello >>> float('Nan') == float('Nan') False Why ? Because the IEEE-754 Standard demands it, and people smarter than I worked on the IEEE-754 Standard. <https://en.wikipedia.org/wiki/NaN> is a quick starting point for a deep

Why float('Nan') == float('Nan') is False

2019-02-13 Thread ast
Hello >>> float('Nan') == float('Nan') False Why ? Regards -- https://mail.python.org/mailman/listinfo/python-list

Re: ValueError: Input contains NaN, infinity or a value too large for dtype('float32')

2019-01-24 Thread Rhodri James
issue but there are no NaN, infinites, negative infinites or large values. I tried to answer it probably because it looked fishy and some people need encouragement to read the fine manual. I don't know for sure, you trimmed all the attribution and I can't find a thread of this name

Re: ValueError: Input contains NaN, infinity or a value too large for dtype('float32')

2019-01-23 Thread paulmattheww
> You may be using the sklearn package incorrectly; you'll > have to read the (apparently quite prolific) documentation yourself, > I've never used it. > > -- > Rhodri James *-* Kynesim Ltd So why would you try to answer it? I have the same issue but there are

Getting Pandas NaT to propagate like NaN

2018-10-30 Thread Skip Montanaro
I'm trying to take the min and max of a couple Pandas Series objects in the face of NaT. np.minimum and np.maximum work the way I want if the elements are floats. For example: >>> s1 00.0 11.8 23.6 35.4 dtype: float64 >>> s2 0 10.0 117.0 2 NaN 3

Re: ValueError: Input contains NaN, infinity or a value too large for dtype('float32')

2017-04-27 Thread Terry Reedy
uot;, line 407, in check_array _assert_all_finite(array) File "/.local/lib/python2.7/site-packages/sklearn/utils/validation.py", line 58, in _assert_all_finite " or a value too large for %r." % X.dtype) ValueError: Input contains NaN, infinity or a value too large

Re: ValueError: Input contains NaN, infinity or a value too large for dtype('float32')

2017-04-27 Thread Rhodri James
array _assert_all_finite(array) File "/.local/lib/python2.7/site-packages/sklearn/utils/validation.py", line 58, in _assert_all_finite " or a value too large for %r." % X.dtype) ValueError: Input contains NaN, infinity or a value too large for dtype('float32

ValueError: Input contains NaN, infinity or a value too large for dtype('float32')

2017-04-27 Thread Siva Kumar S
File "/.local/lib/python2.7/site-packages/sklearn/utils/validation.py", line 58, in _assert_all_finite " or a value too large for %r." % X.dtype) ValueError: Input contains NaN, infinity or a value too large for dtype('float32'). Process finished with exit code 1 Description : Can any one help with the error message. -- https://mail.python.org/mailman/listinfo/python-list

Re: Is nan in (nan,) correct?

2015-03-06 Thread Rustom Mody
ontainer types use a > >> >> hybrid test: "a is b or a == b". > >> >> > >> >> My question is, is this a *correct* implementation of the operator, or > >> >> are objects "supposed to" use a basis of equality for these t

Re: Is nan in (nan,) correct?

2015-03-06 Thread Steven D'Aprano
ver, the >> >> contains operation does not specify whether object identity or >> >> equality is to be used. In effect, the built-in container types use a >> >> hybrid test: "a is b or a == b". >> >> >> >> My question is,

Re: Is nan in (nan,) correct?

2015-03-06 Thread Ethan Furman
e me a little fuller (if not more realistic) example > [Your xx and yy are what?] xx and yy are lists of floats, and for your test xx should have at least one zero in it. > And I have to see if I know how to tweak it nan-less > And at least maintain hopefully improve the clarity, succi

Re: Is nan in (nan,) correct?

2015-03-06 Thread Rustom Mody
mpression (maybe I am wrong): > > "Catch an exception and ignore it" is a way of converting signalling to > > quiet With the added advantage of being able to tweak the specs of what > > happens when nan op normal to one's taste > > > I don't understand

Re: Is nan in (nan,) correct?

2015-03-06 Thread Rustom Mody
w_name point to old implementation To make bar == baz we need more and more heavy-duty theorem provers And will invariably hit halting-problem in some guise or other > > Also, I have no idea what any of this has to do with nans and > container membership. ⊥ in semantics is the prototypica

Re: Is nan in (nan,) correct?

2015-03-06 Thread Chris Angelico
On Sat, Mar 7, 2015 at 4:04 AM, Rustom Mody wrote: > You dont grok your theory of computation very well do you? > > def foo(x): return x + x > def bar(x): return x + x > def baz(x): return 2*x > > One can imagine an implementation where > id(foo) == id(bar) > [I am assuming that id is a good enoug

Re: Is nan in (nan,) correct?

2015-03-06 Thread Steven D'Aprano
v/2014-July/135476.html > > If it is a bug for NaN to "infect" containers' behavior, we need to take > a serious look at sort(). Hmmm. No, I don't think so. I think that NANs are just weird and you either accept that they do weird things or you don't use them. Re

Re: Is nan in (nan,) correct?

2015-03-06 Thread Rustom Mody
ify whether object identity or equality > >> is to be used. In effect, the built-in container types use a hybrid > >> test: "a is b or a == b". > >> > >> My question is, is this a *correct* implementation of the operator, or > >> are objects

Re: Is nan in (nan,) correct?

2015-03-06 Thread Steven D'Aprano
ded advantage of being able to tweak the specs of what > happens when nan op normal to one's taste I don't understand what you are trying to say. Let's take a dirt-simple example: def inverse(x): return 1.0/x There's an exception there, waiting to bite. If I include i

Re: Is nan in (nan,) correct?

2015-03-06 Thread Steven D'Aprano
> test: "a is b or a == b". >> >> My question is, is this a *correct* implementation of the operator, or >> are objects "supposed to" use a basis of equality for these tests? > > nan is an illegal or bogus value. NANs *represent* bogus values, they

Re: Is nan in (nan,) correct?

2015-03-06 Thread Grant Edwards
On 2015-03-06, Chris Angelico wrote: > On Fri, Mar 6, 2015 at 8:50 PM, Rustom Mody wrote: >> In a language like python with decent exceptions we do not need nans. > > Not so. I could perhaps accept that we don't need signalling NaNs, as > they can be replaced with exceptions, but quiet NaNs are b

Re: Is nan in (nan,) correct?

2015-03-06 Thread Rustom Mody
t; they can be replaced with exceptions, but quiet NaNs are by definition > _not_ exceptions. My impression (maybe I am wrong): "Catch an exception and ignore it" is a way of converting signalling to quiet With the added advantage of being able to tweak the specs of what happens when na

Re: Is nan in (nan,) correct?

2015-03-06 Thread Chris Angelico
On Fri, Mar 6, 2015 at 8:50 PM, Rustom Mody wrote: > In a language like python with decent exceptions we do not need nans. Not so. I could perhaps accept that we don't need signalling NaNs, as they can be replaced with exceptions, but quiet NaNs are by definition _not_ exceptions. ChrisA -- htt

Re: Is nan in (nan,) correct?

2015-03-06 Thread Rustom Mody
estion is, is this a *correct* implementation of the operator, or > are objects "supposed to" use a basis of equality for these tests? nan is an illegal or bogus value. As usual legalizing the illegal is always fraught with increasing conundrums. The most (to me) classic instance of thi

Re: Is nan in (nan,) correct?

2015-03-05 Thread Mark Lawrence
.html If it is a bug for NaN to "infect" containers' behavior, we need to take a serious look at sort(). I entirely agree. With the extremely serious bug that was reported (and fixed) just a few days ago in the Python sorting algorithm and/or code, it is quite clear to me

Re: Is nan in (nan,) correct?

2015-03-05 Thread random832
On Thu, Mar 5, 2015, at 22:49, Chris Angelico wrote: > I'm not sure it's just an optimization. Compare this post from > python-dev, where Nick Coghlan discusses the same topic: > > https://mail.python.org/pipermail/python-dev/2014-July/135476.html If it is a bug for NaN

Re: Is nan in (nan,) correct?

2015-03-05 Thread Chris Angelico
On Fri, Mar 6, 2015 at 2:26 PM, Ben Finney wrote: > Isn't the point at issue that the Python interpreter *may* optimise by > assuming ‘is implies equality’, so the ‘in’ operator can fail if that > assumption is false? > > I thought the problem was that types with custom behaviour, as with the > ‘N

Re: Is nan in (nan,) correct?

2015-03-05 Thread Ethan Furman
re? Because True is current behavior. > > Isn't the point at issue that the Python interpreter *may* optimise by > assuming ‘is implies equality’, so the ‘in’ operator can fail if that > assumption is false? No, it's not a /may/, it's a /does/, and that it can be

Re: Is nan in (nan,) correct?

2015-03-05 Thread Ben Finney
Ethan Furman writes: > On 03/05/2015 06:55 PM, Ben Finney wrote: > > > class NullType(object): > > """ A type whose value never equals any other. > > > > This type's values will behave correctly when tested for > > membership in a collection:: > > > >

Re: Is nan in (nan,) correct?

2015-03-05 Thread Ethan Furman
On 03/05/2015 06:55 PM, Ben Finney wrote: > class NullType(object): > """ A type whose value never equals any other. > > This type's values will behave correctly when tested for > membership in a collection:: > > >>> foo = NullType() >

Re: Is nan in (nan,) correct?

2015-03-05 Thread Ben Finney
Steven D'Aprano writes: > Since reflexivity is *almost* universal, and using object identity > permits very substantial optimizations, the core developers agreed > that built-in contain types may assume that `x is y` implies `x == y`. > Users of NANs and other non-reflexive types can subclass or

Re: Is nan in (nan,) correct?

2015-03-05 Thread Steven D'Aprano
random...@fastmail.us wrote: > It's been brought up on Stack Overflow that the "in" operator (on > tuples, and by my testing on dict and list, as well as dict lookup) uses > object identity as a shortcut, and returns true immediately if the > object being tested *is* an element of the container. H

Re: Is nan in (nan,) correct?

2015-03-05 Thread Terry Reedy
Nothing about nans is 'correct'. They are a CS invention On 3/5/2015 5:26 PM, random...@fastmail.us wrote: It's been brought up on Stack Overflow that the "in" operator (on tuples, and by my testing on dict and list, as well as dict lookup) uses object identity as a shortcut, and returns true i

Re: Is nan in (nan,) correct?

2015-03-05 Thread Chris Angelico
On Fri, Mar 6, 2015 at 10:27 AM, wrote: > Do you have an example of where `a is b` but `a != b` in Python? `None == > None` is True. Check out the subject line. >>> nan = float("nan") >>> nan is nan # obviously True >>> nan != nan

Re: Is nan in (nan,) correct?

2015-03-05 Thread Ben Finney
b` in Python? Maybe I misunderstand your question, but you've already been discussing such an example. Here it is for clarity:: >>> nan = float("NaN") >>> (nan is nan) == (nan == nan) False >>> nan is nan True >>> nan == nan

Re: Is nan in (nan,) correct?

2015-03-05 Thread sohcahtoa82
On Thursday, March 5, 2015 at 3:20:16 PM UTC-8, Ben Finney wrote: > sohcahto...@gmail.com writes: > > > I would argue that if `a is b` then it is obvious that `a == b` > > It may be obvious, but it's not necessarily true. Some commonly-used > values - for example, an "null" - are not equal to the

Re: Is nan in (nan,) correct?

2015-03-05 Thread Chris Angelico
On Fri, Mar 6, 2015 at 10:11 AM, wrote: > I would argue that if `a is b` then it is obvious that `a == b` This is not true for float("nan"), though. The question is, is your above statement a valid optimization for the 'in' operator, or not? And no, it isn't, bec

Re: Is nan in (nan,) correct?

2015-03-05 Thread Ben Finney
sohcahto...@gmail.com writes: > I would argue that if `a is b` then it is obvious that `a == b` It may be obvious, but it's not necessarily true. Some commonly-used values – for example, an “null” – are not equal to themselves, by definition. It is fine to define such a type in Python, because ‘

Re: Is nan in (nan,) correct?

2015-03-05 Thread sohcahtoa82
On Thursday, March 5, 2015 at 2:27:12 PM UTC-8, rand...@fastmail.us wrote: > It's been brought up on Stack Overflow that the "in" operator (on > tuples, and by my testing on dict and list, as well as dict lookup) uses > object identity as a shortcut, and returns true immediately if the > object bei

Is nan in (nan,) correct?

2015-03-05 Thread random832
It's been brought up on Stack Overflow that the "in" operator (on tuples, and by my testing on dict and list, as well as dict lookup) uses object identity as a shortcut, and returns true immediately if the object being tested *is* an element of the container. However, the contains operation does no

Re: where in Nan defined

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 1:12 PM, Ian Kelly wrote: > Or to never have to worry about it: > > INF = 1e400 > while not math.isinf(INF): > INF *= INF With no imports whatsoever: inf = 1e400 nan = inf-inf while nan == nan: inf *= inf nan = inf-inf But now we're getti

Re: where in Nan defined

2015-01-08 Thread Ian Kelly
On Thu, Jan 8, 2015 at 7:07 PM, Chris Angelico wrote: > On Fri, Jan 9, 2015 at 12:46 PM, Steven D'Aprano >> The fallback rule I use when float('nan') fails is >> >> INF = 1e3000 # Hopefully, this should overflow to INF. >> NAN = INF-INF # A

Re: where in Nan defined

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 12:46 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> On Fri, Jan 9, 2015 at 1:50 AM, Jussi Piitulainen >> wrote: >>>>>> 0*1e400 >>>nan >> >> Nice, that's shorter than mine. > &

Re: where in Nan defined

2015-01-08 Thread Steven D'Aprano
Chris Angelico wrote: > On Fri, Jan 9, 2015 at 1:50 AM, Jussi Piitulainen > wrote: >>>>> 0*1e400 >>nan > > Nice, that's shorter than mine. o_O Is that really the sort of thing you should be revealing here? Oh wait, you're talking about co

Re: where in Nan defined

2015-01-08 Thread Jussi Piitulainen
Chris Angelico writes: > On Fri, Jan 9, 2015 at 1:37 AM, Marko Rauhamaa wrote: > > > > True, but that got me thinking: what standard Python math > > operation evaluates to NaN? > > Subtracting infinity from infinity is one easy way. > > >>> 1e309 >

Re: where in Nan defined

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 1:50 AM, Jussi Piitulainen wrote: >>>> 0*1e400 >nan Nice, that's shorter than mine. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: where in Nan defined

2015-01-08 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Ian Kelly: > > > To get nan as a literal just do: > > > > nan = float("nan") > > True, but that got me thinking: what standard Python math operation > evaluates to NaN? All manner of arithmetics gives overflow errors (&qu

Re: where in Nan defined

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 1:37 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> To get nan as a literal just do: >> >> nan = float("nan") > > True, but that got me thinking: what standard Python math operation > evaluates to NaN? Subtracting infinity fr

  1   2   3   4   5   >