oracle / graalpython

GraalPy – A high-performance embeddable Python 3 runtime for Java
https://www.graalvm.org/python/
Other
1.24k stars 108 forks source link

Pandas DataFrame error (can't convert negative value to npy_uint8) #253

Closed denrykhlov closed 2 years ago

denrykhlov commented 2 years ago

Hi,

I've tried to run some very basic pandas code from official doc version of 0.25.0.

import numpy as np
import pandas as pd

animals = pd.DataFrame({'kind': ['cat', 'dog', 'cat', 'dog'],
                        'height': [9.1, 6.0, 9.5, 34.0],
                        'weight': [7.9, 7.5, 9.9, 198.0]})
animals

Expected output: graalpython should show the standard pandas dataframe in the SystemOut. Actual output:

>>> animals
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/graalvm/python/lib/python3.8/site-packages/pandas-0.25.0-py3.8-linux-x86_64.egg/pandas/core/frame.py", line 648, in __repr__
    self.to_string(
  File "/home/graalvm/python/lib/python3.8/site-packages/pandas-0.25.0-py3.8-linux-x86_64.egg/pandas/core/frame.py", line 756, in to_string
    formatter.to_string()
  File "/home/graalvm/python/lib/python3.8/site-packages/pandas-0.25.0-py3.8-linux-x86_64.egg/pandas/io/formats/format.py", line 687, in to_string
    strcols = self._to_str_columns()
  File "/home/graalvm/python/lib/python3.8/site-packages/pandas-0.25.0-py3.8-linux-x86_64.egg/pandas/io/formats/format.py", line 625, in _to_str_columns
    fmt_values = self._format_col(i)
  File "/home/graalvm/python/lib/python3.8/site-packages/pandas-0.25.0-py3.8-linux-x86_64.egg/pandas/io/formats/format.py", line 810, in _format_col
    return format_array(
  File "/home/graalvm/python/lib/python3.8/site-packages/pandas-0.25.0-py3.8-linux-x86_64.egg/pandas/io/formats/format.py", line 1032, in format_array
    return fmt_obj.get_result()
  File "/home/graalvm/python/lib/python3.8/site-packages/pandas-0.25.0-py3.8-linux-x86_64.egg/pandas/io/formats/format.py", line 1063, in get_result
    fmt_values = self._format_strings()
  File "/home/graalvm/python/lib/python3.8/site-packages/pandas-0.25.0-py3.8-linux-x86_64.egg/pandas/io/formats/format.py", line 1108, in _format_strings
    is_float_type = lib.map_infer(vals, is_float) & notna(vals)
  File "pandas._libs.lib.map_infer", line 2238, in pandas._libs.lib.map_infer
  File "pandas._libs.lib.maybe_convert_objects", line 2016, in pandas._libs.lib.maybe_convert_objects
OverflowError: can't convert negative value to npy_uint8

Environment information The code had been executed from the official docker image (ghcr.io/graalvm/graalvm-ce:latest).

Numpy and Pandas were install via ginstall command (not via pip).

microdnf install unzip zip patch
graalpython -m ginstall install numpy
graalpython -m ginstall install pandas

graalpython -m venv python
source python/bin/activate

Please, also see the java version and installed python packages in the virtual environment from where the code been executed:

(python) bash-4.4# pip list
Package         Version
--------------- -------
hpy             0.0.3
numpy           1.16.4
pandas          0.25.0
pip             21.3.1
python-dateutil 2.7.5
pytz            2018.7
setuptools      47.1.0
setuptools-scm  1.15.0
six             1.12.0

(python) bash-4.4# java -version
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05)
OpenJDK 64-Bit Server VM GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05, mixed mode, sharing)
msimacek commented 2 years ago

Hi @denrykhlov, thank you for the report. I can reproduce the problem on the released version, but not anymore on the current development version. So it is fixed already, just not yet released. You can get the development version here to test it.