Comparing logical values to NaN in pandas/numpy : <p>I want to do an element-wise OR operation on two pandas Series of boolean values. <code>np.nan</code>s are also included.</p>

<p>I have tried three approaches and realized that the expression "<code>np.nan</code> or <code>False</code>" can be evaluted to <code>True</code>, <code>False</code>, and <code>np.nan</code> depending on the approach.</p>

<p>These are my example Series:  </p>

<pre><code>series_1 = pd.Series([True, False, np.nan])
series_2 = pd.Series([False, False, False])
</code></pre>

<h3>Approach #1</h3>

<p>Using the <code>|</code> operator of pandas:  </p>

<pre><code>In [5]: series_1 | series_2
Out[5]: 
0     True
1    False
2    False
dtype: bool
</code></pre>

<h3>Approach #2</h3>

<p>Using the <code>logical_or</code> function from numpy:</p>

<pre><code>In [6]: np.logical_or(series_1, series_2)
Out[6]: 
0     True
1    False
2      NaN
dtype: object
</code></pre>

<h3>Approach #3</h3>

<p>I define a vectorized version of <code>logical_or</code> which is supposed to be evaluated row-by-row over the arrays:</p>

<pre><code>@np.vectorize
def vectorized_or(a, b):
   return np.logical_or(a, b)
</code></pre>

<p>I use <code>vectorized_or</code> on the two series and convert its output (which is a numpy array) into a pandas Series:</p>

<pre><code>In [8]:  pd.Series(vectorized_or(series_1, series_2))
Out[8]: 
0     True
1    False
2     True
dtype: bool
</code></pre>

<h3>Question</h3>

<p>I am wondering about the reasons for these results.<br>
<a href="https://stackoverflow.com/a/17274707/6295616">This answer</a> explains <code>np.logical_or</code> and says <code>np.logical_or(np.nan, False)</code> is be <code>True</code> but why does this only works when vectorized and not in Approach #2? And how can the results of Approach #1 be explained? </p>
