Skip to content

Commit c942f3f

Browse files
authored
Deprecate the Core helper build_multi_table_dictionary_domain (#395)
Keep the same functionality as a "private" function. Deprecate the usage of the public function. It could be dropped in V11. Also add documentation note to the public function, as to its intent and purpose. closes #386
1 parent 66c9dc9 commit c942f3f

File tree

6 files changed

+84
-12
lines changed

6 files changed

+84
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
### Fixed
1515
- (`sklearn`) Crash when there were no informative trees in predictors.
1616

17+
### Deprecated
18+
- `core`:
19+
- The `build_multi_table_dictionary_domain` helper function.
20+
1721
## 10.3.0.0 - 2025-02-10
1822

1923
### Fixed

khiops/core/api.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import khiops.core.internals.filesystems as fs
2222
from khiops.core.dictionary import DictionaryDomain, read_dictionary_file
2323
from khiops.core.exceptions import KhiopsRuntimeError
24-
from khiops.core.helpers import build_multi_table_dictionary_domain
24+
from khiops.core.helpers import _build_multi_table_dictionary_domain
2525
from khiops.core.internals.common import (
2626
CommandLineOptions,
2727
SystemSettings,
@@ -1943,8 +1943,7 @@ def build_multi_table_dictionary(
19431943
19441944
.. warning::
19451945
This method is *deprecated* since Khiops 10.1.3 and will be removed in Khiops
1946-
11. Use the `.build_multi_table_dictionary_domain` helper function to
1947-
the same effect.
1946+
11.
19481947
19491948
Parameters
19501949
----------
@@ -1979,7 +1978,7 @@ def build_multi_table_dictionary(
19791978
# Generate multi-table domain by using the eponymous helper function
19801979
# Honor exception API:
19811980
try:
1982-
multi_table_domain = build_multi_table_dictionary_domain(
1981+
multi_table_domain = _build_multi_table_dictionary_domain(
19831982
dictionary_domain, root_dictionary_name, secondary_table_variable_name
19841983
)
19851984
except TypeError as error:

khiops/core/helpers.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import platform
1010
import subprocess
11+
import warnings
1112

1213
import khiops.core.internals.filesystems as fs
1314
from khiops.core import api
@@ -19,6 +20,7 @@
1920
)
2021
from khiops.core.internals.common import (
2122
create_unambiguous_khiops_path,
23+
deprecation_message,
2224
is_list_like,
2325
type_error_message,
2426
)
@@ -29,6 +31,22 @@ def build_multi_table_dictionary_domain(
2931
):
3032
"""Builds a multi-table dictionary domain from a dictionary with a key
3133
34+
.. note::
35+
36+
This is a special-purpose function whose goal is to assist in preparing the
37+
coclustering deployment.
38+
39+
This function builds a new root dictionary and adds it to an existing dictionary
40+
domain.
41+
The new root dictionary only contains one field, which references a preexisting
42+
dictionary from the input dictionary domain as a new (secondary) Table variable.
43+
The preexisting dictionary must have a key set on it, as this is the join key
44+
with the new root table.
45+
46+
.. warning::
47+
This method is *deprecated* since Khiops 10.3.1.0 and will be removed in Khiops
48+
11.
49+
3250
Parameters
3351
----------
3452
dictionary_domain : `.DictionaryDomain`
@@ -38,6 +56,11 @@ def build_multi_table_dictionary_domain(
3856
secondary_table_variable_name : str
3957
Name, in the root dictionary, for the "table" variable of the secondary table.
4058
59+
Returns
60+
-------
61+
`.DictionaryDomain`
62+
The new dictionary domain
63+
4164
Raises
4265
------
4366
`TypeError`
@@ -47,6 +70,16 @@ def build_multi_table_dictionary_domain(
4770
- the dictionary domain doesn't contain at least a dictionary
4871
- the dictionary domain's root dictionary doesn't have a key set
4972
"""
73+
# Warn the user that this helper function is deprecated and will be removed
74+
warnings.warn(deprecation_message("build_multi_table_dictionary_domain", "11.0.0"))
75+
return _build_multi_table_dictionary_domain(
76+
dictionary_domain, root_dictionary_name, secondary_table_variable_name
77+
)
78+
79+
80+
def _build_multi_table_dictionary_domain(
81+
dictionary_domain, root_dictionary_name, secondary_table_variable_name
82+
):
5083
# Check that `dictionary_domain` is a `DictionaryDomain`
5184
if not isinstance(dictionary_domain, DictionaryDomain):
5285
raise TypeError(
@@ -266,7 +299,7 @@ def deploy_coclustering(
266299
# Create a root dictionary containing the keys
267300
root_dictionary_name = "CC_" + dictionary_name
268301
table_variable_name = "Table_" + dictionary_name
269-
domain = build_multi_table_dictionary_domain(
302+
domain = _build_multi_table_dictionary_domain(
270303
tmp_domain, root_dictionary_name, table_variable_name
271304
)
272305

khiops/sklearn/estimators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import khiops.core as kh
4545
import khiops.core.internals.filesystems as fs
4646
from khiops.core.dictionary import DictionaryDomain
47-
from khiops.core.helpers import build_multi_table_dictionary_domain
47+
from khiops.core.helpers import _build_multi_table_dictionary_domain
4848
from khiops.core.internals.common import (
4949
deprecation_message,
5050
is_dict_like,
@@ -1037,7 +1037,7 @@ def _create_coclustering_model_domain(
10371037
assert isinstance(output_dir, str)
10381038

10391039
# Build multi-table dictionary domain out of the input domain
1040-
mt_domain = build_multi_table_dictionary_domain(
1040+
mt_domain = _build_multi_table_dictionary_domain(
10411041
domain,
10421042
self.model_main_dictionary_name_,
10431043
self.model_secondary_table_variable_name,

tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,7 @@ def test_build_multi_table_dictionary_behavior(self):
23052305
parameter_trace = KhiopsTestHelper.create_parameter_trace()
23062306

23072307
in_args = KhiopsCoreVariousTests._build_multi_table_dictionary_args()
2308-
helper_name = "build_multi_table_dictionary_domain"
2308+
helper_name = "_build_multi_table_dictionary_domain"
23092309
KhiopsTestHelper.wrap_with_parameter_trace(
23102310
"khiops.core.api", helper_name, parameter_trace
23112311
)

tests/test_helper_functions.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import platform
1212
import stat
1313
import unittest
14+
import warnings
1415

1516
import pandas as pd
1617

@@ -22,10 +23,9 @@
2223
class KhiopsHelperFunctions(unittest.TestCase):
2324
"""Tests for checking the behaviour of the helper functions"""
2425

25-
def test_build_multi_table_dictionary_domain(self):
26-
"""Test that the multi-table dictionary domain built is as expected"""
27-
# Build monotable_domain, with one dictionary, holding three variables
28-
monotable_domain_specification = {
26+
@staticmethod
27+
def _build_monotable_domain_specification():
28+
return {
2929
"tool": "Khiops Dictionary",
3030
"version": "10.0",
3131
"khiops_encoding": "ascii",
@@ -42,6 +42,42 @@ def test_build_multi_table_dictionary_domain(self):
4242
}
4343
],
4444
}
45+
46+
def test_build_multi_table_dictionary_domain_deprecation(self):
47+
"""Test that `core.helpers.build_multi_table_dictionary_domain` raises
48+
deprecation warning
49+
"""
50+
# Build monotable_domain, with one dictionary, holding three variables
51+
monotable_domain_specification = (
52+
KhiopsHelperFunctions._build_monotable_domain_specification()
53+
)
54+
monotable_domain = DictionaryDomain(monotable_domain_specification)
55+
56+
# Build multi-table dictionary domain from the montable dictionary domain
57+
with warnings.catch_warnings(record=True) as warning_list:
58+
build_multi_table_dictionary_domain(
59+
monotable_domain,
60+
"A_Prefix_SpliceJunctionDNA",
61+
"A_Name_SpliceJunctionDNA",
62+
)
63+
64+
self.assertEqual(len(warning_list), 1)
65+
warning = warning_list[0]
66+
self.assertTrue(issubclass(warning.category, UserWarning))
67+
warning_message = warning.message
68+
self.assertEqual(len(warning_message.args), 1)
69+
message = warning_message.args[0]
70+
self.assertTrue(
71+
"'build_multi_table_dictionary_domain'" in message
72+
and "deprecated" in message
73+
)
74+
75+
def test_build_multi_table_dictionary_domain(self):
76+
"""Test that the multi-table dictionary domain built is as expected"""
77+
# Build monotable_domain, with one dictionary, holding three variables
78+
monotable_domain_specification = (
79+
KhiopsHelperFunctions._build_monotable_domain_specification()
80+
)
4581
monotable_domain = DictionaryDomain(monotable_domain_specification)
4682

4783
# Build reference multi-table domain, with two dictionaries, one root

0 commit comments

Comments
 (0)