ValueError: cannot convert float NaN to integer

180 views
Skip to first unread message

David Cohen

unread,
Mar 11, 2021, 8:52:15 PM3/11/21
to OpenQuake Users
I am getting this error, what can I do to I remediate this error?

Kind regards,
David

I am attaching the traceback:

Traceback (most recent call last):

  File "c:\program files\openquake engine\python3.6\lib\site-packages\openquake\engine\engine.py", line 263, in run_calc

    calc.run(exports=exports, **kw)

  File "c:\program files\openquake engine\python3.6\lib\site-packages\openquake\calculators\base.py", line 248, in run

    self.result = self.execute()

  File "c:\program files\openquake engine\python3.6\lib\site-packages\openquake\calculators\classical.py", line 491, in execute

    self.store_info(psd)

  File "c:\program files\openquake engine\python3.6\lib\site-packages\openquake\calculators\classical.py", line 519, in store_info

    numsites / self.numctxs)

  File "c:\program files\openquake engine\python3.6\lib\logging\__init__.py", line 1901, in info

    root.info(msg, *args, **kwargs)

  File "c:\program files\openquake engine\python3.6\lib\logging\__init__.py", line 1307, in info

    self._log(INFO, msg, args, **kwargs)

  File "c:\program files\openquake engine\python3.6\lib\logging\__init__.py", line 1443, in _log

    self.handle(record)

  File "c:\program files\openquake engine\python3.6\lib\logging\__init__.py", line 1453, in handle

    self.callHandlers(record)

  File "c:\program files\openquake engine\python3.6\lib\logging\__init__.py", line 1515, in callHandlers

    hdlr.handle(record)

  File "c:\program files\openquake engine\python3.6\lib\logging\__init__.py", line 864, in handle

    self.emit(record)

  File "c:\program files\openquake engine\python3.6\lib\site-packages\openquake\commonlib\logs.py", line 113, in emit

    record.getMessage())

  File "c:\program files\openquake engine\python3.6\lib\logging\__init__.py", line 338, in getMessage

    msg = msg % self.args

ValueError: cannot convert float NaN to integer

Michele Simionato

unread,
Mar 11, 2021, 11:24:52 PM3/11/21
to OpenQuake Users
You should send the files you are using (the archive generated by oq zip job.ini) so that we can debug the issue.

      Michele

David Cohen

unread,
Mar 12, 2021, 12:16:08 AM3/12/21
to openqua...@googlegroups.com
--
You received this message because you are subscribed to a topic in the Google Groups "OpenQuake Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openquake-users/5UqjSXtDkt0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openquake-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openquake-users/8a2e0c12-0351-4f79-8cc8-532bd64095fdn%40googlegroups.com.


--
Watch your thoughts, for they become words. Watch your words, for they become actions. Watch your actions, for they become habits. Watch your habits, for they become your character. And watch your character, for it becomes your destiny. 

Lao Tzu

Abrahamson.zip

David Cohen

unread,
Mar 12, 2021, 12:17:58 AM3/12/21
to openqua...@googlegroups.com
Michele,

Sorry I accidentally sent the email without message. I am resending now.

Regards  and thanks
David
Abrahamson.zip

David Cohen

unread,
Mar 12, 2021, 1:23:33 AM3/12/21
to OpenQuake Users
Michele,

I found out the problem is with the distance from source to site in my Job.ini file, I increased the distance from 300 km to 400  km and it ran.

Regards,
David

Michele Simionato

unread,
Mar 12, 2021, 5:56:18 AM3/12/21
to OpenQuake Users
Good for you, but I still need to improve the error message ;-)

rahul kumar

unread,
Mar 15, 2021, 1:54:48 AM3/15/21
to OpenQuake Users
You can avoid this with a mask method. Note first that in python NaN is defined as the number which is not equal to itself:

>float('nan') == float('nan')      
False

It might be worth avoiding use of np.NaN altogether. NaN literally means "not a number", and it cannot be converted to an integer.  In general, Python prefers raising an exception to returning NaN, so things like sqrt(-1) and log(0.0) will generally raise instead of returning NaN. However, you may get this value back from some other library.  From v0.24, you actually can. Pandas introduces Nullable Integer Data Types which allows integers to coexist with NaNs.  Also, even at the lastest versions of pandas if the column is object type you would have to convert into float first, something like:

df['column_name'].astype(np.float).astype("Int32")

NB: You have to go through numpy float first and then to nullable Int32, for some reason.
Reply all
Reply to author
Forward
0 new messages