I wonder why does python pandas / numpy not implement 3-valued logic (so-called Łukasiewicz's logic) with true, false and NA (like for instance R does). I've read (https://www.oreilly.com/learning/handling-missing-data) that this is to some extent due to the fact that pandas uses much more many basic data types than R for example. However, this is not entirely clear to me why in this case it is unavoidable to have this weird behaviour of logical operations with missing values.
Example.
import numpy as np
np.nan and False # so far so good, we have False
np.nan or False # again, good, we have nan
False and np.nan # False, good
False or np.nan # give nan, so again, it is correct
np.nan and True # weird, this gives True, while it should give nan
True and np.nan # nan, so it is correct, but switching order should not affect the result
np.nan or True # gives nan, which is not correct, should be True
True or np.nan # True so it is correct, again switching the arguments changes the result
So the example shows that something very weird happens in comparisons between np.nan
and True
values. So what is going on here?
EDIT.
Thanks for the comments, now I see that np.nan
is considered a "truthy" value. So can anybody explain what does this mean exactly and what is a rationale behind this approach?