8000 [MRG] Enable california_housing pandas test in cron job by VarIr · Pull Request #16547 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG] Enable california_housing pandas test in cron job #16547

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

Merged
merged 18 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sklearn/datasets/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" Network tests are only run, if data is already locally available,
or if download is specifically requested by environment variable."""
import builtins
from os import environ
import pytest
from sklearn.datasets import fetch_20newsgroups
Expand Down Expand Up @@ -59,3 +60,16 @@ def fetch_olivetti_faces_fxt():
@pytest.fixture
def fetch_rcv1_fxt():
return _wrapped_fetch(fetch_rcv1, dataset_name='rcv1')


BF12 @pytest.fixture
def hide_available_pandas(monkeypatch):
""" Pretend pandas was not installed. """
import_orig = builtins.__import__

def mocked_import(name, *args, **kwargs):
if name == 'pandas':
raise ImportError()
return import_orig(name, *args, **kwargs)

monkeypatch.setattr(builtins, '__import__', mocked_import)
19 changes: 8 additions & 11 deletions sklearn/datasets/tests/test_california_housing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ def test_fetch_asframe(fetch_california_housing_fxt):
assert isinstance(bunch.target, pd.Series)


def test_pandas_dependency_message(fetch_california_housing_fxt):
try:
import pandas # noqa
pytest.skip("This test requires pandas to be not installed")
except ImportError:
# Check that pandas is imported lazily and that an informative error
# message is raised when pandas is missing:
expected_msg = ('fetch_california_housing with as_frame=True'
' requires pandas')
with pytest.raises(ImportError, match=expected_msg):
fetch_california_housing_fxt(as_frame=True)
def test_pandas_dependency_message(fetch_california_housing_fxt,
hide_available_pandas):
# Check that pandas is imported lazily and that an informative error
# message is raised when pandas is missing:
expected_msg = ('fetch_california_housing with as_frame=True'
' requires pandas')
with pytest.raises(ImportError, match=expected_msg):
fetch_california_housing_fxt(as_frame=True)
0