Setting values for a numpy ndarray using mask
<p>I want to calculate business days between two times, both of which contain null values, following <a href="https://stackoverflow.com/questions/37576552/dealing-with-none-values-when-using-pandas-groupby-and-apply-with-a-function">this question</a> related to calculating business days.  I've identified that the way I'm setting values using a mask does not behave as expected.  </p>

<p>I'm using python 2.7.11, pandas 0.18.1 and numpy 1.11.0. My slightly modified code:</p>

<pre><code>import datetime
import numpy as np
import pandas as pd

def business_date_diff(start, end):
    mask = pd.notnull(start) &amp; pd.notnull(end)
    start = start[mask]
    end = end[mask]
    start = start.values.astype('datetime64[D]')
    end = end.values.astype('datetime64[D]')
    result = np.empty(len(mask), dtype=float)
    result[mask] = np.busday_count(start, end)
    result[~mask] = np.nan
    return result
</code></pre>

<p>Unfortunately, this doesn't return the expected business day differences (instead I get a number of very near 0 floats).  When I check <code>np.busday_count(start, end)</code> the results look correct. </p>

<pre><code>print start[0:5]
print end[0:5]
print np.busday_count(start, end)[0:5]

# ['2016-07-04' '2016-07-04' '2016-07-04' '2016-07-04' '2016-07-04']
# ['2016-07-05' '2016-07-05' '2016-07-05' '2016-07-06' '2016-07-06']
# [1 1 1 2 2]
</code></pre>

<p>But when I check the values for <code>results</code> the results do not make sense:</p>

<pre><code>...
result = np.empty(len(mask), dtype=float)
result[mask] = np.busday_count(start, end)
result[~mask] = np.nan
print result

# [           nan               nan   1.43700866e-210   1.45159738e-210
# 1.45159738e-210   1.45159738e-210   1.45159738e-210   1.46618609e-210
# 1.45159738e-210   1.64491834e-210   1.45159738e-210   1.43700866e-210
# 1.43700866e-210   1.43700866e-210   1.43700866e-210   1.45159738e-210
# 1.43700866e-210   1.43700866e-210   1.43700866e-210   1.43700866e-210
</code></pre>

<p>What am I doing wrong?</p>