Unverified Commit 29857c8a authored by José Morales's avatar José Morales Committed by GitHub
Browse files

[tests][python-package] refactor list_to_1d_numpy test to run without pandas installed (#4639)


Co-authored-by: default avatarNikita Titov <nekit94-12@hotmail.com>
parent 7fa07ee2
...@@ -510,19 +510,23 @@ def test_choose_param_value(): ...@@ -510,19 +510,23 @@ def test_choose_param_value():
assert original_params == expected_params assert original_params == expected_params
@pytest.mark.skipif(not PANDAS_INSTALLED, reason='pandas is not installed') @pytest.mark.parametrize('collection', ['1d_np', '2d_np', 'pd_float', 'pd_str', '1d_list', '2d_list'])
@pytest.mark.parametrize(
'y',
[
np.random.rand(10),
np.random.rand(10, 1),
pd_Series(np.random.rand(10)),
pd_Series(['a', 'b']),
[1] * 10,
[[1], [2]]
])
@pytest.mark.parametrize('dtype', [np.float32, np.float64]) @pytest.mark.parametrize('dtype', [np.float32, np.float64])
def test_list_to_1d_numpy(y, dtype): def test_list_to_1d_numpy(collection, dtype):
collection2y = {
'1d_np': np.random.rand(10),
'2d_np': np.random.rand(10, 1),
'pd_float': np.random.rand(10),
'pd_str': ['a', 'b'],
'1d_list': [1] * 10,
'2d_list': [[1], [2]],
}
y = collection2y[collection]
if collection.startswith('pd'):
if not PANDAS_INSTALLED:
pytest.skip('pandas is not installed')
else:
y = pd_Series(y)
if isinstance(y, np.ndarray) and len(y.shape) == 2: if isinstance(y, np.ndarray) and len(y.shape) == 2:
with pytest.warns(UserWarning, match='column-vector'): with pytest.warns(UserWarning, match='column-vector'):
lgb.basic.list_to_1d_numpy(y) lgb.basic.list_to_1d_numpy(y)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment