Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlondschien committed Jan 14, 2025
1 parent 6b37b34 commit 512550b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 0 additions & 2 deletions python-package/lightgbm/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2187,8 +2187,6 @@ def _lazy_init(
elif isinstance(data, np.ndarray):
self.__init_from_np2d(data, params_str, ref_dataset)
elif _is_pyarrow_table(data):
if not CFFI_INSTALLED:
raise LightGBMError("Cannot init dataframe from Arrow without `pyarrow` and `cffi` installed.")
self.__init_from_pyarrow_table(data, params_str, ref_dataset)
elif isinstance(data, list) and len(data) > 0:
if _is_list_of_numpy_arrays(data):
Expand Down
24 changes: 24 additions & 0 deletions tests/python_package_test/test_arrow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# coding: utf-8
import filecmp
import os
import sys
from pathlib import Path
from typing import Any, Dict, Optional
from unittest import mock

import numpy as np
import pytest
Expand Down Expand Up @@ -454,3 +456,25 @@ def test_arrow_feature_name_manual():
)
booster = lgb.train({"num_leaves": 7}, dataset, num_boost_round=5)
assert booster.feature_name() == ["c", "d"]


def test_training_and_predicting_from_pa_table_without_cffi_raises():
data = generate_dummy_arrow_table()
with mock.patch.dict(sys.modules, {"cffi": None}):
assert lgb.compat.PYARROW_INSTALLED is True

with pytest.raises(
lgb.basic.LightGBMError, match="Cannot init dataframe from Arrow without `pyarrow` and `cffi` installed."
):
dataset = lgb.Dataset(
data,
label=pa.array([0, 1, 0, 0, 1]),
params=dummy_dataset_params(),
feature_name=["c", "d"],
categorical_feature=["c"],
)

with pytest.raises(
lgb.basic.LightGBMError, match="Cannot predict from Arrow without `pyarrow` and `cffi` installed."
):
_ = lgb.train({"num_leaves": 7}, dataset, num_boost_round=5)

0 comments on commit 512550b

Please sign in to comment.