title: Pandas dataframe filtered with np.where returns wrong data
body: <p><em>Python 3.8.10, Pandas 1.4.4, Numpy 1.23.2</em></p>
  <p>I'm receiving a data streaming from a machine every 10 seconds (in the database times are precisely stored every 10 seconds: no 9.5 nor 11).
  The machine goes sometimes in standby so the streaming stops. Occasionally it sends random data when in standby.</p>
  <p>To eliminate the spurious data I use a parameter SECONDS: when set to 10, each line is considered valid if there was a stored line 10 seconds before.</p>
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  
  df = pd.DataFrame(
      {&quot;DT&quot;: [   # two occasional readings
          &quot;2022-09-21 00:38:40&quot;, &quot;2022-09-21 01:59:30&quot;,
          # stable data flow 
          &quot;2022-09-21 04:31:40&quot;, &quot;2022-09-21 04:31:50&quot;,
          &quot;2022-09-21 04:32:00&quot;, &quot;2022-09-21 04:32:10&quot;,
          &quot;2022-09-21 04:32:20&quot;, &quot;2022-09-21 04:32:30&quot;,
          &quot;2022-09-21 04:32:40&quot;, &quot;2022-09-21 04:32:50&quot;,
          # missed one reading here
          &quot;2022-09-21 04:33:10&quot;, &quot;2022-09-21 04:33:20&quot;, 
          &quot;2022-09-21 04:33:30&quot;, &quot;2022-09-21 04:33:40&quot;,
          &quot;2022-09-21 04:33:50&quot;, &quot;2022-09-21 04:34:00&quot;, 
          &quot;2022-09-21 04:34:10&quot;, &quot;2022-09-21 04:34:20&quot;,
          &quot;2022-09-21 04:34:30&quot;
      ], 
       &quot;notes&quot;: [
          &quot;occasional mistake&quot;,
          &quot;occasional mistake&quot;,
          &quot;first stable reading&quot;,
          &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;,
          &quot;one reading missing&quot;,
          &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;
       ] },   
  )
  
  df.DT = df.DT.astype('datetime64[ns]')
  
  SECONDS = 10  # &lt;====== change here the accepted interval 
  
  df[&quot;deltaDT&quot;] = (df[&quot;DT&quot;] - df[&quot;DT&quot;].shift(SECONDS // 10)).dt.total_seconds()
  df[&quot;ok&quot;] = np.where(df[&quot;deltaDT&quot;]==SECONDS, &quot;ok&quot;, &quot;-&quot;)
  
  
  print(df)
  </code></pre>
  <p>This is for me the most intuitive solution, and for 10 seconds it returns the correct answer:
  <a href="https://i.stack.imgur.com/3owRg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3owRg.png" alt="enter image description here" /></a></p>
  <p>(Note: The reading at <code>2022-09-21 04.33.10</code> is lost, not an issue here)</p>
  <p><strong>Problem arise with only some SECONDS values:</strong> 10, 20, 40, 50 are OK. Choosing 30 and 60, the error appears.</p>
  <p>This is SECONDS = 30:</p>
  <p><a href="https://i.stack.imgur.com/PlBvY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PlBvY.png" alt="enter image description here" /></a></p>
  <p>It is obviously a problem related to binary conversion. Quite difficult to spot because  if I am working with floats that really represent only integer values or NaN, there shouldn't be an infinitesimal epsilon involved.</p>
  <p>Changing the filter condition to</p>
  <pre><code>df[&quot;ok&quot;] = np.where(df[&quot;deltaDT&quot;]&lt;=SECONDS+EPSILON, &quot;ok&quot;, &quot;-&quot;)
  </code></pre>
  <p>it return the wrong result for <code>EPSILON=1E-15</code>, and the correct one for <code>EPSILON=1E-14</code>.</p>
  <h2>My question now (sorry I was longer than the Harry Potter saga):</h2>
  <p>How to convert
  <code>df[&quot;deltaDT&quot;] = (df[&quot;DT&quot;] - df[&quot;DT&quot;].shift(SECONDS // 10)).dt.total_seconds()</code> to integer?</p>
  <p>Adding <code>.astype(&quot;Int64&quot;)</code> generates the error &quot;TypeError: cannot safely cast non-equivalent float64 to int64&quot;</p>