diff --git a/Integrations/python/functional-tests/pylong_conv_test.py b/Integrations/python/functional-tests/pylong_conv_test.py new file mode 100644 index 00000000000..01090044236 --- /dev/null +++ b/Integrations/python/functional-tests/pylong_conv_test.py @@ -0,0 +1,22 @@ +# +# Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending +# +import unittest +from deephaven import TableTools +import bootstrap + +long_value = 2 ** 32 + 5 + + +class TestClass(unittest.TestCase): + + def test_long_number_conversion(self): + t = TableTools.emptyTable(1) + result = TableTools.string(t.update("X = long_value"), 1) + self.assertEqual(long_value, int(result.split()[2])) + + +if __name__ == "__main__": + bootstrap.build_py_session() + + unittest.main(verbosity=2) diff --git a/engine/table/src/main/java/io/deephaven/engine/util/PythonScopeJpyImpl.java b/engine/table/src/main/java/io/deephaven/engine/util/PythonScopeJpyImpl.java index 24789f013b2..b3c1163ddd1 100644 --- a/engine/table/src/main/java/io/deephaven/engine/util/PythonScopeJpyImpl.java +++ b/engine/table/src/main/java/io/deephaven/engine/util/PythonScopeJpyImpl.java @@ -189,7 +189,16 @@ public static Object convert(PyObject pyObject) { } else if (pyObject.isCallable()) { return wrapCallable(pyObject); } else if (pyObject.isConvertible()) { - return pyObject.getObjectValue(); + Object objValue = pyObject.getObjectValue(); + // workaround a JPY issue with determining the correct Java type a Python 'int' should be + // mapped to (int or long) without causing an implicit overflow + if (objValue instanceof Integer) { + long longValue; + if ((longValue = pyObject.getLongValue()) != (int) objValue) { + return longValue; + } + } + return objValue; } else { return pyObject; }