Fixed #23770 -- Changed serialization strategy for floats with respect to NaN and Inf

Thanks to w0rp for the report
It's just a habit of mine to separate `import` from `from ... import ...`. Changed it.