code: def _json_safe_float(number):
      
      if number is None:
          return None
  
      if isinstance(number, float):
          return None if np.isinf(number) or np.isnan(number) else number
  
      # errors if number is not float compatible
      return float(number)
docs: JSON serialization for infinity can be problematic.
      See https://docs.python.org/2/library/json.html#basic-usage
      This function returns None if `number` is infinity or negative infinity.
  
      If the `number` cannot be converted to float, this will raise an exception.