title: Python custom JSON encoder isn't handling numpy NaN or Infinite values
body: <p>So I'm trying to write a custom encoder that handles different <code>numpy</code> values:</p>
  
  <pre><code>class NumpyEncoder(DjangoJSONEncoder):
      def default(self, obj):
          if isinstance(obj, np.integer):
              return int(obj)
          elif isinstance(obj, np.floating):
              return float(obj)
          elif isinstance(obj, np.ndarray):
              return obj.tolist()
          if np.isnan(obj) or np.isinf(obj):
              return None
          else:
              return super().default(obj)
  </code></pre>
  
  <p>However, it doesn't appear to be handling <code>np.NaN</code> or <code>np.inf</code> objects:</p>
  
  <pre><code>obj = {'test': np.NaN, 'test2': np.inf}
  json.dumps(obj, cls=LazyNumpyEncoder)
  Out[5]: '{"test": NaN, "test2": Infinity}'
  </code></pre>
  
  <p>I've also tried using <code>elif isinstance(obj, np.nan):</code>, but that hasn't worked either. </p>
  
  <p>What I want is my <code>NaN</code> and Infinite (including negative infinite values) to be turned into nulls. </p>
  
  <p>Anyone know where I've gone wrong? </p>