Skip to content

Commit bfca18b

Browse files
committed
Fixed nan/inf bugs
1 parent e0d6b89 commit bfca18b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/PythonExtension.scala

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package org.nlogo.extensions.py
22

3+
import com.fasterxml.jackson.core.json.JsonReadFeature
4+
import com.fasterxml.jackson.databind.json.JsonMapper
5+
import com.fasterxml.jackson.databind.ObjectMapper
6+
37
import java.io.{ BufferedReader, Closeable, File, IOException, InputStreamReader }
48
import java.lang.ProcessBuilder.Redirect
59
import java.nio.file.Paths
610

7-
import com.fasterxml.jackson.core.json.JsonReadFeature
8-
import com.fasterxml.jackson.databind.json.JsonMapper
11+
import org.json4s.jackson.{ JsonMethods, Json4sScalaModule }
912

1013
import org.nlogo.languagelibrary.Subprocess.path
1114
import org.nlogo.languagelibrary.Subprocess
@@ -65,7 +68,6 @@ class PythonExtension extends api.DefaultClassManager {
6568

6669
override def runOnce(em: ExtensionManager): Unit = {
6770
super.runOnce(em)
68-
JsonMapper.builder().configure(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS, true)
6971

7072
val py2Message = s"It is recommended to use Python 3 if possible and enter its path above. If you must use Python 2, enter the path to its executable folder below."
7173
val py2Property = new FileProperty("python2", "python2", PythonExtension.config.get("python2").getOrElse(""), py2Message)
@@ -127,7 +129,13 @@ object SetupPython extends api.Command {
127129
val pyFile = if (maybePyFile.exists) { maybePyFile } else { (new File("pyext.py")).getCanonicalFile }
128130
val pyScript: String = pyFile.toString
129131
try {
130-
PythonExtension.pythonProcess = Subprocess.start(context.workspace, pythonCmd, Seq(pyScript), PythonExtension.codeName, PythonExtension.longName)
132+
val mapper = new JsonMethods {
133+
override def mapper: ObjectMapper =
134+
JsonMapper.builder.addModule(new Json4sScalaModule).enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS).build()
135+
}
136+
PythonExtension.pythonProcess = Subprocess.start(context.workspace, pythonCmd, Seq(pyScript),
137+
PythonExtension.codeName, PythonExtension.longName,
138+
customMapper = Option(mapper))
131139
PythonExtension.menu.foreach(_.setup(PythonExtension.pythonProcess.evalStringified))
132140
} catch {
133141
case e: Exception =>

0 commit comments

Comments
 (0)