This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2017-11-23.08:44:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
"ValueError: cannot convert float NaN to integer": this error occurred on int(float), where the float comes from os.stat()

File "<frozen importlib._bootstrap_external>", line 762, in get_code


def get_code(self, fullname):
    st = self.path_stats(source_path)
    source_mtime = int(st['mtime']) <~~~~~~ HERE

def path_stats(self, path):
    st = _path_stat(path)
    return {'mtime': st.st_mtime, 'size': st.st_size}

def _path_stat(path):
    return _os.stat(path)

=> The float NaN comes from os.stat().st_mtime.

Implementation of os.stat().st_mtime in Modules/posixmodule.c:

static PyObject*
_pystat_fromstructstat(STRUCT_STAT *st)
#if defined(HAVE_STAT_TV_NSEC)
    ansec = st->st_atim.tv_nsec;
    mnsec = st->st_mtim.tv_nsec;
    cnsec = st->st_ctim.tv_nsec;
#elif defined(HAVE_STAT_TV_NSEC2)
    ansec = st->st_atimespec.tv_nsec;
    mnsec = st->st_mtimespec.tv_nsec;
    cnsec = st->st_ctimespec.tv_nsec;
#elif defined(HAVE_STAT_NSEC)
    ansec = st->st_atime_nsec;
    mnsec = st->st_mtime_nsec;
    cnsec = st->st_ctime_nsec;
    ansec = mnsec = cnsec = 0;
    fill_time(v, 7, st->st_atime, ansec);
    fill_time(v, 8, st->st_mtime, mnsec);
    fill_time(v, 9, st->st_ctime, cnsec);

static void
fill_time(PyObject *v, int index, time_t sec, unsigned long nsec)
    float_s = PyFloat_FromDouble(sec + 1e-9*nsec);  <~~~~~~ HERE
    PyStructSequence_SET_ITEM(v, index+3, float_s);

Extract of the ./configure script output:

checking for tv_nsec in struct stat... no
checking for tv_nsec2 in struct stat... yes

=> configure defines HAVE_STAT_TV_NSEC2

We need sec and nsec values from fill_time() to debug this issue.
Date User Action Args
2017-11-23 08:44:11vstinnersetrecipients: + vstinner
2017-11-23 08:44:11vstinnersetmessageid: <>
2017-11-23 08:44:11vstinnerlinkissue32119 messages
2017-11-23 08:44:11vstinnercreate