« first day (4372 days earlier)      last day (575 days later) » 

12:02 AM
(Pdb) print(f"{id(float('nan'))} {id(float('nan'))}")
140062674023216 140062674023216
(Pdb) float("nan") is float("nan")
False
seems almost like a bug because the id is the same but the is operator fails?
 
12:26 AM
3
Q: What is the intuitive reason that NaN != NaN?

Maile CupoFrom what I have been able to find, the IEEE defines NaN to not equal itself in the floating point number system. The only time I've ever had to compare NaN to NaN is in comparing dataframe entries, in which case this property of NaN is actually a big nuisance. Was just wondering why the decisi...

just following standards
 
My comment was different
I can live with float("nan") == float("nan") because thats running comparison on the value
but id and is are running comparisons on the underlying address of the PyObject*
 
Oh, what you did is something else completely different, unrelated to floats
Have to find the thread
 
either line of code may or may not produce the same object. It has nothing to do with the special comparison behaviour of nan.
is should only be used in code that consciously and deliberately controls object identity.
(for example, to detect cycles or joins in a graph)
 
>>> g = float('nan')
>>> g is g
it prints out True
 
different numeric objects are permitted to have different values, even if that value is something special like nan. There is nothing that prevents the existence of two separate objects (which therefore compare false with is) that are both the floating-point NaN, just like there is nothing to prevent the existence of two separate objects that are both strings with the same content.
immutability enables interning; it is not a guarantee.
 
12:38 AM
`print(f"{id(float('nan'))} {id(float('nan'))}")`
140062674023216 140062674023216

shows they are the same object?
they have the same id!!!!
 
That's probably because Python discarded the first value as the refcount decreased after it got used, and the second call just reused the address
If you force it to an assignment, you will get a different value, which you can do using the walrus operator (I hate this thing but this shows what you actually did)
>>> print(f"{id(f:=float('nan'))} {id(g:=float('nan'))}")
140221994058384 140221994058736
>>> f
nan
>>> g
nan
>>> f is g
False
they happened to have the same id purely because how cpython happens to operate, the result of the first float('nan') got discarded because it isn't needed after being passed to id(...), so the subsequent call can reuse the same address, but this is a purely implementation detail
my example force the result to be bounded to some variable (through :=), and thus subsequent call can't reuse the same memory address
Same thing can be replicated using object()
>>> print(f"{id(object())} {id(object())}")
140221995213952 140221995213952
>>> print(f"{id(g:=object())} {id(h:=object())}")
140221995213952 140221995213968
you can't be telling me all calls to object() gives the same address, right? then the idea of using object() as unique sentinel objects completely falls apart
@Mikhail Finally, this thread is the canonical thread for your question.
Also this [note](https://docs.python.org/3.10/reference/expressions.html#id20) in the documentation:
> Due to automatic garbage-collection, free lists, and the dynamic nature of descriptors, you may notice seemingly unusual behaviour in certain uses of the `is` operator, like those involving comparisons between instance methods, or constants. Check their documentation for more info.
 
 
1 hour later…
2:02 AM
nice demonstration
 
2:22 AM
honestly, this is one of the more benign sharp edges I rubbed over for this language
now that one with class "scopes", lol
 
 
10 hours later…
12:13 PM
One thing that I occasionally find helpful when doing bare-metal work on floats: you can use the struct module to view their internal bits. pastebin.com/raw/n2q693aJ
Interestingly, nan and negative nan have different bit representations, even though they both look like "nan" when you print them
 
Does going async in FastAPI mean changing a lot of code? That is, when switching to async db calls my whole code.
 
I'm inclined to say "no"
 
I don't know much about FastAPI, but probably not. Should just be a matter of sprinkling in a few asyncs and awaits
 
nice
 
It's crazy how you essentially forget a lot of your programming skills just by switching to a different language. In python, it's probably been a decade since I used dicts instead of classes. In TypeScript? Lots of dicts. Lots of magic strings instead of enums. And lots of time spent trying to convince TypeScript that my magic strings are a type.
And now that I've switched to classes, lots of toString() implementations so I get more useful output than [Object object].
It was also interesting to see the contrast between python and a language with powerful static code analysis like TS. In python, I pay zero attention to VSCode's red and yellow squiggles. In TS, I spend hours eliminating all of them
 
12:30 PM
What are your thoughts on VSCode vs PyCharm?
 
It's been quite a while since I used PyCharm, but I didn't like it because it was so slow and unresponsive. I switched to VSCode primarily because it was fast, even though the python support back then was terrible
Nowadays, I'm not even sure if PyCharm's python support is still better than VSCode's
As long as you use PyLance, anyway. Jedi and whatever-that-other-one-was-called are just bad
 
I've never used VSCode so i m kind of biased but I ve seen from my colleagues that PyCharm is probably better when it comes to static code analysis.
It does have a few annoying bugs though (recent versions) that VSCode didn't have. Not that many tbh
 
Logged in to say that both are bad
 
Is there more you wanted to say or is that it? :D
 
I was about to ask what to use then :P
 
12:44 PM
@Aran-Fey I also came prepared to argue about it
Maybe even offer my recommendation of a flawed text editor that I personally use
 
I'm torn. On one hand, all software that's more complex than "Hello World" is bad. On the other hand, VSCode is very low on my list of programs that I have complaints about
 
@Riya VSCode supports so many languages that it's almost a no-brainer for me to prefer it over PyCharm
 
brief cbg all
 
1:03 PM
@roganjosh Indeed. That's a huge plus. On the other hand PyCharm (especially professional) seems to come with batteries included. Many things can be done with a few clicks. I donno. Perhaps same goes for VSCode. I m not very familiar with it.
 
1:19 PM
hello all
how to create timelines in python? is there any library that I can use to create timelines for project management
 
Well, you could always make one yourself by drawing shapes and text with PIL
 
Looks like plotly can do gantt charts. We were just complaining about plotly the other day.
 
2:02 PM
@Riya what do you envision can be done with a few clicks that VSCode might not be able to do?
 
make a decent cup of tea?
 
I'm pretty happy with PyCharm just because it doesn't bug me with pages of potentially-super-awesome plugins for everything.
VSCode is pretty nice for cross-language development, though.
 
 
1 hour later…
3:08 PM
hi @Mike!
(puppy_ninja here - thanks for popping your head in :p)
 
3:27 PM
Hi!
This place seems like it is pretty quiet
 
well don't look into other SO chat rooms then
 
I'm not complaining. It's actually kind of nice. Makes it easier to follow a conversation
 
it has bursts of chat
this time of day though it's generally quieter as the US/Western Europe are still in "office hours" as it were
 
 
8 hours later…
11:54 PM
usually by the time I have my coffee it's quiet, lol
 

« first day (4372 days earlier)      last day (575 days later) »