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

[python-package] Tests not running without pandas (tests.python_package_test/test_basic.py) #4638

Closed
strobelTha opened this issue Oct 1, 2021 · 2 comments · Fixed by #4639
Labels

Comments

@strobelTha
Copy link
Contributor

Description

If running pytest without an installation of pandas no test is executed and the run is stopped with the following error message:

python_package_test/test_basic.py:519: in <module>
    ???
E   TypeError: pd_Series() takes no arguments

In that line, we can find a test that seems to be supposedly skipped if pandas is not installed. But as far as I know pytest.mark.parametrize is evaluated anyways, making the whole test suit crash. I'm honestly not sure if this is an error on my side. But it looks like an easy thing to oversee if you have pandas installed by default, so I thought I should mention it here.

@pytest.mark.skipif(not PANDAS_INSTALLED, reason='pandas is not installed')
@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])
def test_list_to_1d_numpy(y, dtype):
    if isinstance(y, np.ndarray) and len(y.shape) == 2:
        with pytest.warns(UserWarning, match='column-vector'):
            lgb.basic.list_to_1d_numpy(y)
        return
    elif isinstance(y, list) and isinstance(y[0], list):
        with pytest.raises(TypeError):
            lgb.basic.list_to_1d_numpy(y)
        return
    elif isinstance(y, pd_Series) and y.dtype == object:
        with pytest.raises(ValueError):
            lgb.basic.list_to_1d_numpy(y)
        return
    result = lgb.basic.list_to_1d_numpy(y, dtype=dtype)
    assert result.size == 10
    assert result.dtype == dtype

Reproducible example

pytest tests/python_package_test

Environment info

LightGBM version or commit hash:
3.2.1.99

Command(s) you used to install LightGBM

# install the Python package
git submodule init
git submodule update --recursive
cd python-package
python setup.py install
@strobelTha strobelTha changed the title [python-package] Tests not running without panda (tests.python_package_test/test_basic.py) [python-package] Tests not running without pandas (tests.python_package_test/test_basic.py) Oct 1, 2021
@jmoralez
Copy link
Collaborator

jmoralez commented Oct 1, 2021

Thanks for raising this, that's definitely my bad. Will open a PR with a fix.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants