Skip to content

Optionally run tests with pandas #369

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 6 commits into from
Oct 11, 2022
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
22 changes: 18 additions & 4 deletions adaptive/tests/test_average_learner1d.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from itertools import chain

import numpy as np
import pandas as pd
from pandas.testing import assert_series_equal

from adaptive import AverageLearner1D
from adaptive.tests.test_learners import (
Expand All @@ -11,13 +11,27 @@


def almost_equal_dicts(a, b):
assert_series_equal(pd.Series(sorted(a.items())), pd.Series(sorted(b.items())))
assert a.keys() == b.keys()
for k, v1 in a.items():
v2 = b[k]
if (
v1 is None
or v2 is None
or isinstance(v1, (tuple, list))
and any(x is None for x in chain(v1, v2))
):
assert v1 == v2
else:
try:
np.testing.assert_almost_equal(v1, v2)
except TypeError:
raise AssertionError(f"{v1} != {v2}")


def test_tell_many_at_point():
f = generate_random_parametrization(noisy_peak)
learner = AverageLearner1D(f, bounds=(-2, 2))
control = AverageLearner1D(f, bounds=(-2, 2))
control = learner.new()
learner._recompute_losses_factor = 1
control._recompute_losses_factor = 1
simple_run(learner, 100)
Expand Down
5 changes: 4 additions & 1 deletion adaptive/tests/test_learners.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import flaky
import numpy as np
import pandas
import pytest
import scipy.spatial

Expand All @@ -28,6 +27,7 @@
LearnerND,
SequenceLearner,
)
from adaptive.learner.learner1D import with_pandas
from adaptive.runner import simple

try:
Expand Down Expand Up @@ -708,6 +708,7 @@ def wrapper(*args, **kwargs):
return wrapper


@pytest.mark.skipif(not with_pandas, reason="pandas is not installed")
@run_with(
Learner1D,
Learner2D,
Expand All @@ -719,6 +720,8 @@ def wrapper(*args, **kwargs):
with_all_loss_functions=False,
)
def test_to_dataframe(learner_type, f, learner_kwargs):
import pandas

if learner_type is LearnerND:
kw = {"point_names": tuple("xyz")[: len(learner_kwargs["bounds"])]}
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def get_version_and_cmdclass(package_name):
"holoviews>=1.9.1",
"ipywidgets",
"bokeh",
"pandas",
"matplotlib",
"plotly",
],
Expand All @@ -52,7 +53,6 @@ def get_version_and_cmdclass(package_name):
"pytest-randomly",
"pytest-timeout",
"pre_commit",
"pandas",
"typeguard",
],
"other": [
Expand Down