title: Why does pandas Series.replace change the data type when to_replace includes nan?
body: <p>Is there a reason why adding <code>{nan: nan}</code> changes the data type in <code>Series.replace</code>? If yes, what is the intent of having such a behaviour?</p>
  
  <p>This is what I expected:</p>
  
  <pre><code>from pandas import Series
  from numpy import nan
  
  series = Series(['Y', 'N', 'Unknown', nan])
  series.replace({'Y': False, 'N': True, 'Unknown': nan})
  
  0    False
  1     True
  2      NaN
  3      NaN
  dtype: object
  </code></pre>
  
  <p>And this is what I got after adding an "innocent" identity mapping of <code>NaN</code>:</p>
  
  <pre><code>series.replace({'Y': False, 'N': True, 'Unknown': nan, nan: nan})
  0    0.0
  1    1.0
  2    NaN
  3    NaN
  dtype: float64
  </code></pre>
  
  <p>The example looks silly out of the context - in reality, the identity mapping was introduced incidentally when the mapping dictionary (also used elsewhere in the code) was modified.</p>
  
  <p>Background: I am cleaning a DataFrame that includes both NaNs and  "Unknown". As each column is considered on its own (sometimes <em>Unknown</em> is the desired value!) I did not instruct pandas to treat "Unknown" as NaN during data loading.</p>
  
  <p>Related:
  <a href="https://stackoverflow.com/q/21733802/6646912">Pandas Series.replace on boolean Series</a> (5 years old, not related to NaNs and fixed)</p>