title: Passing input of a function returning NaN in Python
body: <p>I am using <a href="https://emcee.readthedocs.io/en/stable/" rel="nofollow noreferrer">EMCEE</a>. I write a part which problem is risen from there in the following.
  I ran into this error
  <code>ValueError: lnprob returned NaN.</code></p>
  
  <p>this error interrupts the calculation and I do not know how to overcome. So, I should do something to pass this error in order to continue the rest of computation.</p>
  
  <p>The only things came to my mind is to add a line in <code>lnprob</code> function like: </p>
  
  <pre><code> if not np.isfinite(lp):
          return -np.inf
   if  np.isnan(lp):
          return -np.inf
  </code></pre>
  
  <p>but it is not correct</p>
  
  <p>the code is:</p>
  
  <pre><code>def log_prior(H0, od0, c, b, Orc, M):
      if  0.4 &lt; od0 &lt; 0.9 and  50 &lt; H0 &lt; 90  and  0 &lt; c &lt; 3 and  0 &lt; b &lt; 1  and  -0.3 &lt; M &lt; 0.2 and  0 &lt; Orc &lt; 0.1:
          return 0.0
      return -np.inf
  
  def lnlike(H0, od0, c, b, Orc, M):
      lg = -chi2(H0, od0, c, b, Orc, M)/2.
      return lg
  
  def lnprob(H0, od0, c, b, Orc, M):
      lp = log_prior(H0, od0, c, b, Orc, M)
      if not np.isfinite(lp):
          return -np.inf
      return lp + lnlike(H0, od0, c, b, Orc, M)
  
  def func(theta):
      H0, od0, c, b, Orc, M = theta
      return -2. * lnprob(H0, od0, c, b, Orc, M)
  </code></pre>
  
  <p>I appreciate your help.</p>