-
-
Notifications
You must be signed in to change notification settings - Fork 270
Expand file tree
/
Copy pathtest_supervised_task.py
More file actions
44 lines (33 loc) · 1.32 KB
/
test_supervised_task.py
File metadata and controls
44 lines (33 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# License: BSD 3-Clause
from __future__ import annotations
import unittest
from unittest.mock import MagicMock, patch
import pandas as pd
from openml.tasks import TaskType
from .test_task import OpenMLTaskTest
class OpenMLSupervisedTaskTest(OpenMLTaskTest):
__test__ = False
@classmethod
def setUpClass(cls):
if cls is OpenMLSupervisedTaskTest:
raise unittest.SkipTest("Skip OpenMLSupervisedTaskTest tests, it's a base class")
super().setUpClass()
def setUp(self, _n_levels: int = 1):
super().setUp()
def test_get_X_and_Y(self) -> tuple[pd.DataFrame, pd.Series]:
if self.task_type == TaskType.SUPERVISED_REGRESSION:
mock_X = pd.DataFrame({f"f_{i}": [float(i)] * 194 for i in range(32)})
mock_y = pd.Series([0.0] * 194)
else:
mock_X = pd.DataFrame({f"f_{i}": [float(i)] * 768 for i in range(8)})
mock_y = pd.Series(["tested_negative"] * 768, dtype="category")
mock_task = MagicMock()
mock_task.get_X_and_y.return_value = (
mock_X,
mock_y,
)
with patch("openml.tasks.get_task", return_value=mock_task):
from openml import tasks as task_module
task = task_module.get_task(self.task_id)
X, Y = task.get_X_and_y()
return X, Y