clj-python / libpython-clj

Python bindings for Clojure
Eclipse Public License 2.0
1.08k stars 68 forks source link

Large integers fail to convert to the JVM #164

Closed cnuernber closed 3 years ago

cnuernber commented 3 years ago
$ cat foo.py

def bar():
    return 9223372036854775808

after requiring,

user=> (py/cfn foo/bar)

Execution error at libpython-clj2.python.ffi/check-error-throw (ffi.clj:684).

OverflowError: int too big to convert

Not certain the best way to address this but it most likely involves bignums :-).

cnuernber commented 3 years ago

Potential fix in 2.00-beta-18. Asking user to test once release is out and will reopen or open further issues if there are failures.

matthewdowney commented 3 years ago

Fwiw I have been able to get around this by using pr-str and read-string, since the values are printing fine at the REPL.

E.g. (-> (foo/bar) pr-str read-string).

cnuernber commented 3 years ago

That is definitely worth a lot, thanks for sharing!. Glad you found a work around. A side note is that a numpy array of big values also won't convert and those are definitely also fixable but they will currently fail to convert correctly.