Skip to content
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

[ci] [python] reduce unnecessary data loading in tests #3486

Merged
merged 16 commits into from
Oct 29, 2020
Merged
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ htmlcov/
.coverage.*
.cache
nosetests.xml
prof/
*.prof
coverage.xml
*,cover
.hypothesis/
Expand Down
Empty file.
13 changes: 10 additions & 3 deletions tests/python_package_test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@
from sklearn.datasets import load_breast_cancer, dump_svmlight_file, load_svmlight_file
from sklearn.model_selection import train_test_split

from .utils import lru_cache


@lru_cache(maxsize=None)
def _load_breast_cancer(**kwargs):
return load_breast_cancer(**kwargs)


class TestBasic(unittest.TestCase):

def test(self):
X_train, X_test, y_train, y_test = train_test_split(*load_breast_cancer(return_X_y=True),
X_train, X_test, y_train, y_test = train_test_split(*_load_breast_cancer(return_X_y=True),
test_size=0.1, random_state=2)
train_data = lgb.Dataset(X_train, label=y_train)
valid_data = train_data.create_valid(X_test, label=y_test)
Expand Down Expand Up @@ -86,7 +93,7 @@ def test(self):
os.remove(tname)

def test_chunked_dataset(self):
X_train, X_test, y_train, y_test = train_test_split(*load_breast_cancer(return_X_y=True), test_size=0.1, random_state=2)
X_train, X_test, y_train, y_test = train_test_split(*_load_breast_cancer(return_X_y=True), test_size=0.1, random_state=2)

chunk_size = X_train.shape[0] // 10 + 1
X_train = [X_train[i * chunk_size:(i + 1) * chunk_size, :] for i in range(X_train.shape[0] // chunk_size + 1)]
Expand Down Expand Up @@ -309,7 +316,7 @@ def check_asserts(data):
self.assertAlmostEqual(data.label[1], data.weight[1])
self.assertListEqual(data.feature_name, data.get_feature_name())

X, y = load_breast_cancer(return_X_y=True)
X, y = _load_breast_cancer(return_X_y=True)
sequence = np.ones(y.shape[0])
sequence[0] = np.nan
sequence[1] = np.inf
Expand Down
Loading