scikit-base 0.4.6__py3-none-any.whl → 0.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docs/source/conf.py +299 -299
- {scikit_base-0.4.6.dist-info → scikit_base-0.5.1.dist-info}/LICENSE +29 -29
- {scikit_base-0.4.6.dist-info → scikit_base-0.5.1.dist-info}/METADATA +160 -159
- scikit_base-0.5.1.dist-info/RECORD +58 -0
- {scikit_base-0.4.6.dist-info → scikit_base-0.5.1.dist-info}/WHEEL +1 -1
- scikit_base-0.5.1.dist-info/top_level.txt +5 -0
- {scikit_base-0.4.6.dist-info → scikit_base-0.5.1.dist-info}/zip-safe +1 -1
- skbase/__init__.py +14 -14
- skbase/_exceptions.py +31 -31
- skbase/_nopytest_tests.py +35 -35
- skbase/base/__init__.py +20 -20
- skbase/base/_base.py +1249 -1249
- skbase/base/_meta.py +883 -871
- skbase/base/_pretty_printing/__init__.py +11 -11
- skbase/base/_pretty_printing/_object_html_repr.py +392 -392
- skbase/base/_pretty_printing/_pprint.py +412 -412
- skbase/base/_tagmanager.py +217 -217
- skbase/lookup/__init__.py +31 -31
- skbase/lookup/_lookup.py +1009 -1009
- skbase/lookup/tests/__init__.py +2 -2
- skbase/lookup/tests/test_lookup.py +991 -991
- skbase/testing/__init__.py +12 -12
- skbase/testing/test_all_objects.py +852 -856
- skbase/testing/utils/__init__.py +5 -5
- skbase/testing/utils/_conditional_fixtures.py +209 -209
- skbase/testing/utils/_dependencies.py +15 -15
- skbase/testing/utils/deep_equals.py +15 -15
- skbase/testing/utils/inspect.py +30 -30
- skbase/testing/utils/tests/__init__.py +2 -2
- skbase/testing/utils/tests/test_check_dependencies.py +49 -49
- skbase/testing/utils/tests/test_deep_equals.py +66 -66
- skbase/tests/__init__.py +2 -2
- skbase/tests/conftest.py +273 -273
- skbase/tests/mock_package/__init__.py +5 -5
- skbase/tests/mock_package/test_mock_package.py +74 -74
- skbase/tests/test_base.py +1202 -1202
- skbase/tests/test_baseestimator.py +130 -130
- skbase/tests/test_exceptions.py +23 -23
- skbase/tests/test_meta.py +170 -131
- skbase/utils/__init__.py +21 -21
- skbase/utils/_check.py +53 -53
- skbase/utils/_iter.py +238 -238
- skbase/utils/_nested_iter.py +180 -180
- skbase/utils/_utils.py +91 -91
- skbase/utils/deep_equals.py +358 -358
- skbase/utils/dependencies/__init__.py +11 -11
- skbase/utils/dependencies/_dependencies.py +253 -253
- skbase/utils/tests/__init__.py +4 -4
- skbase/utils/tests/test_check.py +24 -24
- skbase/utils/tests/test_iter.py +127 -127
- skbase/utils/tests/test_nested_iter.py +84 -84
- skbase/utils/tests/test_utils.py +37 -37
- skbase/validate/__init__.py +22 -22
- skbase/validate/_named_objects.py +403 -403
- skbase/validate/_types.py +345 -345
- skbase/validate/tests/__init__.py +2 -2
- skbase/validate/tests/test_iterable_named_objects.py +200 -200
- skbase/validate/tests/test_type_validations.py +370 -370
- scikit_base-0.4.6.dist-info/RECORD +0 -58
- scikit_base-0.4.6.dist-info/top_level.txt +0 -2
@@ -1,2 +1,2 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
"""Tests of skbase.validate functionality."""
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""Tests of skbase.validate functionality."""
|
@@ -1,200 +1,200 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
# copyright: skbase developers, BSD-3-Clause License (see LICENSE file)
|
3
|
-
"""Tests of the functionality for validating iterables of named objects.
|
4
|
-
|
5
|
-
tests in this module include:
|
6
|
-
|
7
|
-
- test_is_named_object_tuple_output
|
8
|
-
- test_is_sequence_named_objects_output
|
9
|
-
- test_check_sequence_named_objects_output
|
10
|
-
"""
|
11
|
-
|
12
|
-
__author__ = ["RNKuhns"]
|
13
|
-
import pytest
|
14
|
-
|
15
|
-
from skbase.base import BaseEstimator, BaseObject
|
16
|
-
from skbase.validate import (
|
17
|
-
check_sequence_named_objects,
|
18
|
-
is_named_object_tuple,
|
19
|
-
is_sequence_named_objects,
|
20
|
-
)
|
21
|
-
|
22
|
-
|
23
|
-
@pytest.fixture
|
24
|
-
def fixture_object_instance():
|
25
|
-
"""Pytest fixture of BaseObject instance."""
|
26
|
-
return BaseObject()
|
27
|
-
|
28
|
-
|
29
|
-
@pytest.fixture
|
30
|
-
def fixture_estimator_instance():
|
31
|
-
"""Pytest fixture of BaseEstimator instance."""
|
32
|
-
return BaseEstimator()
|
33
|
-
|
34
|
-
|
35
|
-
def test_is_named_object_tuple_output(
|
36
|
-
fixture_estimator_instance, fixture_object_instance
|
37
|
-
):
|
38
|
-
"""Test is_named_object_tuple returns expected value."""
|
39
|
-
# Default checks for object to be an instance of BaseOBject
|
40
|
-
assert is_named_object_tuple(("Step 1", fixture_object_instance)) is True
|
41
|
-
assert is_named_object_tuple(("Step 2", fixture_estimator_instance)) is True
|
42
|
-
|
43
|
-
# If a different `object_type` is provided then it is used in the isinstance check
|
44
|
-
|
45
|
-
assert (
|
46
|
-
is_named_object_tuple(
|
47
|
-
("Step 1", fixture_object_instance), object_type=BaseEstimator
|
48
|
-
)
|
49
|
-
is False
|
50
|
-
)
|
51
|
-
assert (
|
52
|
-
is_named_object_tuple(
|
53
|
-
("Step 1", fixture_estimator_instance), object_type=BaseEstimator
|
54
|
-
)
|
55
|
-
is True
|
56
|
-
)
|
57
|
-
|
58
|
-
# If the input is does not follow named object tuple format then False is returned
|
59
|
-
# This checks for named object tuples, so dictionary input is not allowed
|
60
|
-
assert is_named_object_tuple({"Step 1": fixture_estimator_instance}) is False
|
61
|
-
# First element of tuple must be string
|
62
|
-
assert is_named_object_tuple((1, fixture_object_instance)) is False
|
63
|
-
|
64
|
-
|
65
|
-
def test_is_sequence_named_objects_output(
|
66
|
-
fixture_estimator_instance, fixture_object_instance
|
67
|
-
):
|
68
|
-
"""Test is_sequence_named_objects returns expected value."""
|
69
|
-
# Correctly formatted iterables of (name, BaseObject instance) tuples
|
70
|
-
named_objects = [
|
71
|
-
("Step 1", fixture_estimator_instance),
|
72
|
-
("Step 2", fixture_object_instance),
|
73
|
-
]
|
74
|
-
assert is_sequence_named_objects(named_objects) is True
|
75
|
-
assert is_sequence_named_objects(tuple(named_objects)) is True
|
76
|
-
|
77
|
-
# Test correct format, but duplicate names
|
78
|
-
named_objects = [
|
79
|
-
("Step 1", fixture_estimator_instance),
|
80
|
-
("Step 1", fixture_object_instance),
|
81
|
-
]
|
82
|
-
assert is_sequence_named_objects(named_objects) is True
|
83
|
-
assert is_sequence_named_objects(tuple(named_objects)) is True
|
84
|
-
# Tests with correctly formatted dictionary
|
85
|
-
dict_named_objects = {
|
86
|
-
"Step 1": fixture_estimator_instance,
|
87
|
-
"Step 2": fixture_object_instance,
|
88
|
-
}
|
89
|
-
assert is_sequence_named_objects(dict_named_objects) is True
|
90
|
-
assert is_sequence_named_objects(dict_named_objects, allow_dict=False) is False
|
91
|
-
|
92
|
-
# Invalid format due to object names not being strings
|
93
|
-
incorrectly_named_objects = [
|
94
|
-
(1, fixture_estimator_instance),
|
95
|
-
(2, fixture_object_instance),
|
96
|
-
]
|
97
|
-
assert is_sequence_named_objects(incorrectly_named_objects) is False
|
98
|
-
|
99
|
-
# Invalid format due to named items not being BaseObject instances
|
100
|
-
named_items = [("1", 7), ("2", 42)]
|
101
|
-
assert is_sequence_named_objects(named_items) is False
|
102
|
-
dict_named_objects = {"Step 1": 7, "Step 2": 42}
|
103
|
-
assert is_sequence_named_objects(dict_named_objects) is False
|
104
|
-
|
105
|
-
# Invalid because input is not a sequence
|
106
|
-
non_sequence = 7
|
107
|
-
assert is_sequence_named_objects(non_sequence) is False
|
108
|
-
|
109
|
-
# Generators are also invalid since they don't have length or ability
|
110
|
-
# to access individual elements, we don't includein the named object API
|
111
|
-
named_objects = [
|
112
|
-
("Step 1", fixture_estimator_instance),
|
113
|
-
("Step 2", fixture_object_instance),
|
114
|
-
]
|
115
|
-
assert is_sequence_named_objects(c for c in named_objects) is False
|
116
|
-
|
117
|
-
# Validate use of object_type parameter
|
118
|
-
# Won't work because one named object is a BaseObject but not a BaseEstimator
|
119
|
-
assert is_sequence_named_objects(named_objects, object_type=BaseEstimator) is False
|
120
|
-
|
121
|
-
# Should work because we allow BaseObject or BaseEstimator types
|
122
|
-
named_objects = [("Step 1", BaseEstimator()), ("Step 2", BaseEstimator())]
|
123
|
-
assert (
|
124
|
-
is_sequence_named_objects(
|
125
|
-
named_objects, object_type=(BaseObject, BaseEstimator)
|
126
|
-
)
|
127
|
-
is True
|
128
|
-
)
|
129
|
-
assert is_sequence_named_objects(named_objects, object_type=BaseEstimator) is True
|
130
|
-
|
131
|
-
|
132
|
-
def test_check_sequence_named_objects_output(
|
133
|
-
fixture_estimator_instance, fixture_object_instance
|
134
|
-
):
|
135
|
-
"""Test check_sequence_named_objects returns expected value."""
|
136
|
-
# Correctly formatted iterables of (name, BaseObject instance) tuples
|
137
|
-
named_objects = [
|
138
|
-
("Step 1", fixture_estimator_instance),
|
139
|
-
("Step 2", fixture_object_instance),
|
140
|
-
]
|
141
|
-
assert check_sequence_named_objects(named_objects) == named_objects
|
142
|
-
assert check_sequence_named_objects(tuple(named_objects)) == tuple(named_objects)
|
143
|
-
|
144
|
-
# Tests with correctly formatted dictionary
|
145
|
-
dict_named_objects = {
|
146
|
-
"Step 1": fixture_estimator_instance,
|
147
|
-
"Step 2": fixture_object_instance,
|
148
|
-
}
|
149
|
-
assert check_sequence_named_objects(dict_named_objects) == dict_named_objects
|
150
|
-
# Raises an error if we don't allow dicts as part of named object API
|
151
|
-
with pytest.raises(ValueError):
|
152
|
-
check_sequence_named_objects(dict_named_objects, allow_dict=False)
|
153
|
-
|
154
|
-
# Invalid format due to object names not being strings
|
155
|
-
incorrectly_named_objects = [
|
156
|
-
(1, fixture_estimator_instance),
|
157
|
-
(2, fixture_object_instance),
|
158
|
-
]
|
159
|
-
with pytest.raises(ValueError):
|
160
|
-
check_sequence_named_objects(incorrectly_named_objects)
|
161
|
-
|
162
|
-
# Invalid format due to named items not being BaseObject instances
|
163
|
-
named_items = [("1", 7), ("2", 42)]
|
164
|
-
with pytest.raises(ValueError):
|
165
|
-
check_sequence_named_objects(named_items)
|
166
|
-
dict_named_objects = {"Step 1": 7, "Step 2": 42}
|
167
|
-
with pytest.raises(ValueError):
|
168
|
-
check_sequence_named_objects(dict_named_objects)
|
169
|
-
|
170
|
-
# Invalid due to not being sequences
|
171
|
-
non_sequence = 7
|
172
|
-
with pytest.raises(ValueError):
|
173
|
-
check_sequence_named_objects(non_sequence)
|
174
|
-
|
175
|
-
# Generators are also invalid since they don't have length or ability
|
176
|
-
# to access individual elements, we don't includein the named object API
|
177
|
-
named_objects = [
|
178
|
-
("Step 1", fixture_estimator_instance),
|
179
|
-
("Step 2", fixture_object_instance),
|
180
|
-
]
|
181
|
-
with pytest.raises(ValueError):
|
182
|
-
check_sequence_named_objects(c for c in named_objects)
|
183
|
-
|
184
|
-
# Validate use of object_type parameter
|
185
|
-
# Won't work because one named object is a BaseObject but not a BaseEstimator
|
186
|
-
with pytest.raises(ValueError):
|
187
|
-
check_sequence_named_objects(named_objects, object_type=BaseEstimator)
|
188
|
-
|
189
|
-
# Should work because we allow BaseObject or BaseEstimator types
|
190
|
-
named_objects = [("Step 1", BaseEstimator()), ("Step 2", BaseEstimator())]
|
191
|
-
assert (
|
192
|
-
check_sequence_named_objects(
|
193
|
-
named_objects, object_type=(BaseObject, BaseEstimator)
|
194
|
-
)
|
195
|
-
== named_objects
|
196
|
-
)
|
197
|
-
assert (
|
198
|
-
check_sequence_named_objects(named_objects, object_type=BaseEstimator)
|
199
|
-
== named_objects
|
200
|
-
)
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# copyright: skbase developers, BSD-3-Clause License (see LICENSE file)
|
3
|
+
"""Tests of the functionality for validating iterables of named objects.
|
4
|
+
|
5
|
+
tests in this module include:
|
6
|
+
|
7
|
+
- test_is_named_object_tuple_output
|
8
|
+
- test_is_sequence_named_objects_output
|
9
|
+
- test_check_sequence_named_objects_output
|
10
|
+
"""
|
11
|
+
|
12
|
+
__author__ = ["RNKuhns"]
|
13
|
+
import pytest
|
14
|
+
|
15
|
+
from skbase.base import BaseEstimator, BaseObject
|
16
|
+
from skbase.validate import (
|
17
|
+
check_sequence_named_objects,
|
18
|
+
is_named_object_tuple,
|
19
|
+
is_sequence_named_objects,
|
20
|
+
)
|
21
|
+
|
22
|
+
|
23
|
+
@pytest.fixture
|
24
|
+
def fixture_object_instance():
|
25
|
+
"""Pytest fixture of BaseObject instance."""
|
26
|
+
return BaseObject()
|
27
|
+
|
28
|
+
|
29
|
+
@pytest.fixture
|
30
|
+
def fixture_estimator_instance():
|
31
|
+
"""Pytest fixture of BaseEstimator instance."""
|
32
|
+
return BaseEstimator()
|
33
|
+
|
34
|
+
|
35
|
+
def test_is_named_object_tuple_output(
|
36
|
+
fixture_estimator_instance, fixture_object_instance
|
37
|
+
):
|
38
|
+
"""Test is_named_object_tuple returns expected value."""
|
39
|
+
# Default checks for object to be an instance of BaseOBject
|
40
|
+
assert is_named_object_tuple(("Step 1", fixture_object_instance)) is True
|
41
|
+
assert is_named_object_tuple(("Step 2", fixture_estimator_instance)) is True
|
42
|
+
|
43
|
+
# If a different `object_type` is provided then it is used in the isinstance check
|
44
|
+
|
45
|
+
assert (
|
46
|
+
is_named_object_tuple(
|
47
|
+
("Step 1", fixture_object_instance), object_type=BaseEstimator
|
48
|
+
)
|
49
|
+
is False
|
50
|
+
)
|
51
|
+
assert (
|
52
|
+
is_named_object_tuple(
|
53
|
+
("Step 1", fixture_estimator_instance), object_type=BaseEstimator
|
54
|
+
)
|
55
|
+
is True
|
56
|
+
)
|
57
|
+
|
58
|
+
# If the input is does not follow named object tuple format then False is returned
|
59
|
+
# This checks for named object tuples, so dictionary input is not allowed
|
60
|
+
assert is_named_object_tuple({"Step 1": fixture_estimator_instance}) is False
|
61
|
+
# First element of tuple must be string
|
62
|
+
assert is_named_object_tuple((1, fixture_object_instance)) is False
|
63
|
+
|
64
|
+
|
65
|
+
def test_is_sequence_named_objects_output(
|
66
|
+
fixture_estimator_instance, fixture_object_instance
|
67
|
+
):
|
68
|
+
"""Test is_sequence_named_objects returns expected value."""
|
69
|
+
# Correctly formatted iterables of (name, BaseObject instance) tuples
|
70
|
+
named_objects = [
|
71
|
+
("Step 1", fixture_estimator_instance),
|
72
|
+
("Step 2", fixture_object_instance),
|
73
|
+
]
|
74
|
+
assert is_sequence_named_objects(named_objects) is True
|
75
|
+
assert is_sequence_named_objects(tuple(named_objects)) is True
|
76
|
+
|
77
|
+
# Test correct format, but duplicate names
|
78
|
+
named_objects = [
|
79
|
+
("Step 1", fixture_estimator_instance),
|
80
|
+
("Step 1", fixture_object_instance),
|
81
|
+
]
|
82
|
+
assert is_sequence_named_objects(named_objects) is True
|
83
|
+
assert is_sequence_named_objects(tuple(named_objects)) is True
|
84
|
+
# Tests with correctly formatted dictionary
|
85
|
+
dict_named_objects = {
|
86
|
+
"Step 1": fixture_estimator_instance,
|
87
|
+
"Step 2": fixture_object_instance,
|
88
|
+
}
|
89
|
+
assert is_sequence_named_objects(dict_named_objects) is True
|
90
|
+
assert is_sequence_named_objects(dict_named_objects, allow_dict=False) is False
|
91
|
+
|
92
|
+
# Invalid format due to object names not being strings
|
93
|
+
incorrectly_named_objects = [
|
94
|
+
(1, fixture_estimator_instance),
|
95
|
+
(2, fixture_object_instance),
|
96
|
+
]
|
97
|
+
assert is_sequence_named_objects(incorrectly_named_objects) is False
|
98
|
+
|
99
|
+
# Invalid format due to named items not being BaseObject instances
|
100
|
+
named_items = [("1", 7), ("2", 42)]
|
101
|
+
assert is_sequence_named_objects(named_items) is False
|
102
|
+
dict_named_objects = {"Step 1": 7, "Step 2": 42}
|
103
|
+
assert is_sequence_named_objects(dict_named_objects) is False
|
104
|
+
|
105
|
+
# Invalid because input is not a sequence
|
106
|
+
non_sequence = 7
|
107
|
+
assert is_sequence_named_objects(non_sequence) is False
|
108
|
+
|
109
|
+
# Generators are also invalid since they don't have length or ability
|
110
|
+
# to access individual elements, we don't includein the named object API
|
111
|
+
named_objects = [
|
112
|
+
("Step 1", fixture_estimator_instance),
|
113
|
+
("Step 2", fixture_object_instance),
|
114
|
+
]
|
115
|
+
assert is_sequence_named_objects(c for c in named_objects) is False
|
116
|
+
|
117
|
+
# Validate use of object_type parameter
|
118
|
+
# Won't work because one named object is a BaseObject but not a BaseEstimator
|
119
|
+
assert is_sequence_named_objects(named_objects, object_type=BaseEstimator) is False
|
120
|
+
|
121
|
+
# Should work because we allow BaseObject or BaseEstimator types
|
122
|
+
named_objects = [("Step 1", BaseEstimator()), ("Step 2", BaseEstimator())]
|
123
|
+
assert (
|
124
|
+
is_sequence_named_objects(
|
125
|
+
named_objects, object_type=(BaseObject, BaseEstimator)
|
126
|
+
)
|
127
|
+
is True
|
128
|
+
)
|
129
|
+
assert is_sequence_named_objects(named_objects, object_type=BaseEstimator) is True
|
130
|
+
|
131
|
+
|
132
|
+
def test_check_sequence_named_objects_output(
|
133
|
+
fixture_estimator_instance, fixture_object_instance
|
134
|
+
):
|
135
|
+
"""Test check_sequence_named_objects returns expected value."""
|
136
|
+
# Correctly formatted iterables of (name, BaseObject instance) tuples
|
137
|
+
named_objects = [
|
138
|
+
("Step 1", fixture_estimator_instance),
|
139
|
+
("Step 2", fixture_object_instance),
|
140
|
+
]
|
141
|
+
assert check_sequence_named_objects(named_objects) == named_objects
|
142
|
+
assert check_sequence_named_objects(tuple(named_objects)) == tuple(named_objects)
|
143
|
+
|
144
|
+
# Tests with correctly formatted dictionary
|
145
|
+
dict_named_objects = {
|
146
|
+
"Step 1": fixture_estimator_instance,
|
147
|
+
"Step 2": fixture_object_instance,
|
148
|
+
}
|
149
|
+
assert check_sequence_named_objects(dict_named_objects) == dict_named_objects
|
150
|
+
# Raises an error if we don't allow dicts as part of named object API
|
151
|
+
with pytest.raises(ValueError):
|
152
|
+
check_sequence_named_objects(dict_named_objects, allow_dict=False)
|
153
|
+
|
154
|
+
# Invalid format due to object names not being strings
|
155
|
+
incorrectly_named_objects = [
|
156
|
+
(1, fixture_estimator_instance),
|
157
|
+
(2, fixture_object_instance),
|
158
|
+
]
|
159
|
+
with pytest.raises(ValueError):
|
160
|
+
check_sequence_named_objects(incorrectly_named_objects)
|
161
|
+
|
162
|
+
# Invalid format due to named items not being BaseObject instances
|
163
|
+
named_items = [("1", 7), ("2", 42)]
|
164
|
+
with pytest.raises(ValueError):
|
165
|
+
check_sequence_named_objects(named_items)
|
166
|
+
dict_named_objects = {"Step 1": 7, "Step 2": 42}
|
167
|
+
with pytest.raises(ValueError):
|
168
|
+
check_sequence_named_objects(dict_named_objects)
|
169
|
+
|
170
|
+
# Invalid due to not being sequences
|
171
|
+
non_sequence = 7
|
172
|
+
with pytest.raises(ValueError):
|
173
|
+
check_sequence_named_objects(non_sequence)
|
174
|
+
|
175
|
+
# Generators are also invalid since they don't have length or ability
|
176
|
+
# to access individual elements, we don't includein the named object API
|
177
|
+
named_objects = [
|
178
|
+
("Step 1", fixture_estimator_instance),
|
179
|
+
("Step 2", fixture_object_instance),
|
180
|
+
]
|
181
|
+
with pytest.raises(ValueError):
|
182
|
+
check_sequence_named_objects(c for c in named_objects)
|
183
|
+
|
184
|
+
# Validate use of object_type parameter
|
185
|
+
# Won't work because one named object is a BaseObject but not a BaseEstimator
|
186
|
+
with pytest.raises(ValueError):
|
187
|
+
check_sequence_named_objects(named_objects, object_type=BaseEstimator)
|
188
|
+
|
189
|
+
# Should work because we allow BaseObject or BaseEstimator types
|
190
|
+
named_objects = [("Step 1", BaseEstimator()), ("Step 2", BaseEstimator())]
|
191
|
+
assert (
|
192
|
+
check_sequence_named_objects(
|
193
|
+
named_objects, object_type=(BaseObject, BaseEstimator)
|
194
|
+
)
|
195
|
+
== named_objects
|
196
|
+
)
|
197
|
+
assert (
|
198
|
+
check_sequence_named_objects(named_objects, object_type=BaseEstimator)
|
199
|
+
== named_objects
|
200
|
+
)
|