Author gregory.p.smith
Recipients gregory.p.smith
Date 2016-03-30.07:17:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
time.localtime(float("NaN")) raises a ValueError on x86_64 using the few compilers I have tested it with. (this makes sense)

>>> time.localtime(float("NaN"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: (75, 'Value too large for defined data type')

On an arm and arm64 system, it does not and treats NaN as 0. (nonsense!)

>>> time.localtime(float("NaN"))
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)

The root of this problem appears to be the (potentially questionable? I'll ask a C compiler person...) code in Python/pytime.c's (3.x) Modules/timemodule.c's (2.7) double to time_t conversion function.

I'm not sure what it does is supposed to be well defined behavior with NaN...

The easy fix is to add:

#include <math.h>


add || isnan(x) || isinf(x) to the check that raises a ValueError in (3.x) (2.7)

Along with a relevant assertRaises(ValueError) unittest for NaN, inf and -inf in
Date User Action Args
2016-03-30 07:17:23gregory.p.smithsetrecipients: + gregory.p.smith
2016-03-30 07:17:23gregory.p.smithsetmessageid: <>
2016-03-30 07:17:23gregory.p.smithlinkissue26669 messages
2016-03-30 07:17:22gregory.p.smithcreate