Skip to content

Commit

Permalink
A workaround to a JPY issue with long values, fixes #1461 (#1843)
Browse files Browse the repository at this point in the history
 A workaround to a JPY issue with long values
  • Loading branch information
jmao-denver committed Jan 20, 2022
1 parent ee923cc commit c5214cf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Integrations/python/functional-tests/pylong_conv_test.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c5214cf

Please sign in to comment.