def handle_nan(value):
 if isinstance(value, float):
  if (value == float('inf')):
   return '<inf>'
  if (value == float('-inf')):
   return '<-inf>'
  if (value != value):
   return '<nan>'
 return value

def handle_nan ( value ) : if isinstance ( value , float ) : if ( value == float ( 'inf' ) ) : return '<inf>' if ( value == float ( '-inf' ) ) : return '<-inf>' if ( value != value ) : return '<nan>' return value
remove nan values that cant be json encoded .