-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[python-package] Unexpected behaviour if pyarrow
is installed, but cffi
is not
#6782
Comments
pyarrow
is installed, but cffi
is notpyarrow
is installed, but cffi
is not
Hey @mlondschien, thanks for using LightGBM. How did you install the library? The arrow extra takes this into account LightGBM/python-package/pyproject.toml Lines 36 to 39 in e0c34e7
|
I installed
|
pyarrow
is installed, but cffi
is notpyarrow
is installed, but cffi
is not
Thanks for this report and the thorough investigation! We've been relying on the I'm supportive of your proposal to split up the imports in However, instead of a warning, I think cases like these: LightGBM/python-package/lightgbm/basic.py Lines 1709 to 1710 in e0c34e7
LightGBM/python-package/lightgbm/basic.py Lines 2461 to 2462 in e0c34e7
Should still be exceptions, but like this: if not (CFFI_INSTALLED and PYARROW_INSTALLED):
raise LightGBMError("Cannot predict on Arrow data without 'cffi' and 'pyarrow' installed.") In the case you mentioned ( LightGBM/python-package/lightgbm/basic.py Line 2186 in e0c34e7
So you'd end up with this proposed more-informative error instead of this one: LightGBM/python-package/lightgbm/basic.py Lines 2205 to 2206 in e0c34e7
@jmoralez what do you think about this idea? |
I came across this when debugging #6780.
If
pyarrow
is installed, butcffi
is not, this importLightGBM/python-package/lightgbm/compat.py
Line 292 in e0c34e7
raises, such that
pa_Table
is a dummy class and the comparisonisinstance(data, pa_Table)
returnsFalse
, and so does_is_pyarrow_table
. If fitting on algbm.Dataset(data=pyarrow.Table)
, we thus don't evalute__init_from_pyarrow_table
hereLightGBM/python-package/lightgbm/basic.py
Lines 2186 to 2188 in e0c34e7
but rather jump into the
try / except
here:LightGBM/python-package/lightgbm/basic.py
Lines 2202 to 2206 in e0c34e7
This works, but I am not sure whether this is intended behaviour.
One approach to solve this would be to separate the
pyarrow
andcffi
imports incompat.py
. However, then, jumping intoself.__init_from_pyarrow_table(data, params_str, ref_dataset)
fails, as this requirescffi
to be installed.The underlying problem here is that both
cffi
andpyarrow
need to be installed to "natively" fit from apyarrow.Table
. However, this is not communicated to the user. One approach would be to separate as below, add aand CFFI_INSTALLED
to theelif _is_pyarrow_table(data):
row and raise a warning ifpyarrow
is installed bycffi
is not.The text was updated successfully, but these errors were encountered: