You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
raises, such that pa_Table is a dummy class and the comparison isinstance(data, pa_Table) returns False, and so does _is_pyarrow_table. If fitting on a lgbm.Dataset(data=pyarrow.Table), we thus don't evalute __init_from_pyarrow_table here
raiseTypeError(f"Cannot initialize Dataset from {type(data).__name__}") fromerr
This works, but I am not sure whether this is intended behaviour.
One approach to solve this would be to separate the pyarrow and cffi imports in compat.py. However, then, jumping into self.__init_from_pyarrow_table(data, params_str, ref_dataset) fails, as this requires cffi to be installed.
The underlying problem here is that both cffi and pyarrow need to be installed to "natively" fit from a pyarrow.Table. However, this is not communicated to the user. One approach would be to separate as below, add a and CFFI_INSTALLED to the elif _is_pyarrow_table(data): row and raise a warning if pyarrow is installed by cffi is not.
"""pyarrow"""try:
importpyarrow.computeaspa_computefrompyarrowimportArrayaspa_ArrayfrompyarrowimportChunkedArrayaspa_ChunkedArrayfrompyarrowimportTableaspa_Tablefrompyarrowimportchunked_arrayaspa_chunked_arrayfrompyarrow.typesimportis_booleanasarrow_is_booleanfrompyarrow.typesimportis_floatingasarrow_is_floatingfrompyarrow.typesimportis_integerasarrow_is_integerPYARROW_INSTALLED=TrueexceptImportError:
PYARROW_INSTALLED=Falseclasspa_Array: # type: ignore"""Dummy class for pa.Array."""def__init__(self, *args: Any, **kwargs: Any):
passclasspa_ChunkedArray: # type: ignore"""Dummy class for pa.ChunkedArray."""def__init__(self, *args: Any, **kwargs: Any):
passclasspa_Table: # type: ignore"""Dummy class for pa.Table."""def__init__(self, *args: Any, **kwargs: Any):
passclasspa_compute: # type: ignore"""Dummy class for pyarrow.compute."""all=Noneequal=Nonepa_chunked_array=Nonearrow_is_boolean=Nonearrow_is_integer=Nonearrow_is_floating=None"""cffi"""try:
frompyarrow.cffiimportffiasarrow_cffiCFFI_INSTALLED=TrueexceptImportError:
CFFI_INSTALLED=Falseclassarrow_cffi: # type: ignore"""Dummy class for pyarrow.cffi.ffi."""CData=Noneaddressof=Nonecast=Nonenew=Nonedef__init__(self, *args: Any, **kwargs: Any):
pass
The text was updated successfully, but these errors were encountered:
jameslamb
changed the title
Unexpected behaviour if pyarrow is installed, but cffi is not
[pythong-package] Unexpected behaviour if pyarrow is installed, but cffi is not
Jan 9, 2025
jameslamb
changed the title
[pythong-package] Unexpected behaviour if pyarrow is installed, but cffi is not
[python-package] Unexpected behaviour if pyarrow is installed, but cffi is not
Jan 9, 2025
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: