|
| 1 | +from mock import patch |
| 2 | + |
1 | 3 | import woodwork as ww |
2 | 4 | from woodwork.accessor_utils import _is_koalas_series |
3 | 5 | from woodwork.logical_types import ( |
|
15 | 17 | Unknown, |
16 | 18 | ) |
17 | 19 | from woodwork.tests.testing_utils import to_pandas |
| 20 | +from woodwork.type_sys.type_system import ( |
| 21 | + DEFAULT_INFERENCE_FUNCTIONS, |
| 22 | + DEFAULT_RELATIONSHIPS, |
| 23 | + DEFAULT_TYPE, |
| 24 | + TypeSystem, |
| 25 | +) |
18 | 26 | from woodwork.utils import import_or_none |
19 | 27 |
|
20 | 28 | UNSUPPORTED_KOALAS_DTYPES = [ |
@@ -125,6 +133,47 @@ def test_natural_language_inference(natural_language): |
125 | 133 | assert isinstance(inferred_type, NaturalLanguage) |
126 | 134 |
|
127 | 135 |
|
| 136 | +@patch("woodwork.type_sys.inference_functions.natural_language_func") |
| 137 | +def test_nl_inference_called_on_no_other_matches(nl_mock, pandas_natural_language): |
| 138 | + assert isinstance( |
| 139 | + ww.type_system.infer_logical_type(pandas_natural_language[0]), NaturalLanguage |
| 140 | + ) |
| 141 | + new_type_sys = TypeSystem( |
| 142 | + inference_functions=DEFAULT_INFERENCE_FUNCTIONS, |
| 143 | + relationships=DEFAULT_RELATIONSHIPS, |
| 144 | + default_type=DEFAULT_TYPE, |
| 145 | + ) |
| 146 | + new_type_sys.inference_functions[NaturalLanguage] = nl_mock |
| 147 | + _ = new_type_sys.infer_logical_type(pandas_natural_language[0]) |
| 148 | + assert nl_mock.called |
| 149 | + |
| 150 | + |
| 151 | +@patch("woodwork.type_sys.inference_functions.natural_language_func") |
| 152 | +def test_nl_inference_called_with_unknown_type(nl_mock, pandas_strings): |
| 153 | + assert isinstance(ww.type_system.infer_logical_type(pandas_strings[0]), Unknown) |
| 154 | + new_type_sys = TypeSystem( |
| 155 | + inference_functions=DEFAULT_INFERENCE_FUNCTIONS, |
| 156 | + relationships=DEFAULT_RELATIONSHIPS, |
| 157 | + default_type=DEFAULT_TYPE, |
| 158 | + ) |
| 159 | + new_type_sys.inference_functions[NaturalLanguage] = nl_mock |
| 160 | + _ = new_type_sys.infer_logical_type(pandas_strings[0]) |
| 161 | + assert nl_mock.called |
| 162 | + |
| 163 | + |
| 164 | +@patch("woodwork.type_sys.inference_functions.natural_language_func") |
| 165 | +def test_nl_inference_not_called_with_other_matches(nl_mock, pandas_integers): |
| 166 | + assert isinstance(ww.type_system.infer_logical_type(pandas_integers[0]), Integer) |
| 167 | + new_type_sys = TypeSystem( |
| 168 | + inference_functions=DEFAULT_INFERENCE_FUNCTIONS, |
| 169 | + relationships=DEFAULT_RELATIONSHIPS, |
| 170 | + default_type=DEFAULT_TYPE, |
| 171 | + ) |
| 172 | + new_type_sys.inference_functions[NaturalLanguage] = nl_mock |
| 173 | + _ = new_type_sys.infer_logical_type(pandas_integers[0]) |
| 174 | + assert not nl_mock.called |
| 175 | + |
| 176 | + |
128 | 177 | def test_categorical_inference_based_on_dtype(categories_dtype): |
129 | 178 | """ |
130 | 179 | This test specifically targets the case in which a series can be inferred |
|
0 commit comments