diff --git a/CHANGELOG.md b/CHANGELOG.md index f15c72dc..b3aa42f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Fixed - (`core`) Fix a RuntimeException error when automatically correcting deprecated data paths in task args +- (`sklearn`) Consider all the string dtypes when guessing Khiops types. ## 11.0.1.0 - 2026-07-02 diff --git a/khiops/sklearn/dataset.py b/khiops/sklearn/dataset.py index 1d8d36da..0a20f0cd 100644 --- a/khiops/sklearn/dataset.py +++ b/khiops/sklearn/dataset.py @@ -286,7 +286,7 @@ def get_khiops_type(numpy_type, categorical_str_max_size=None): # float, int, uint types elif "int" in lower_numpy_type or "float" in lower_numpy_type: khiops_type = "Numerical" - elif lower_numpy_type == "string": + elif lower_numpy_type in ("str", "string"): if categorical_str_max_size is not None and categorical_str_max_size > 100: khiops_type = "Text" else: diff --git a/tests/test_dataset_class.py b/tests/test_dataset_class.py index c9dfc4b5..27b38651 100644 --- a/tests/test_dataset_class.py +++ b/tests/test_dataset_class.py @@ -17,7 +17,7 @@ from pandas.testing import assert_frame_equal from sklearn import datasets -from khiops.sklearn.dataset import Dataset, _upgrade_mapping_spec +from khiops.sklearn.dataset import Dataset, PandasTable, _upgrade_mapping_spec class DatasetInputOutputConsistencyTests(unittest.TestCase): @@ -832,3 +832,27 @@ def test_newlines_removed_from_csv_file_for_khiops(self): out_table.Title[0], "Newlines should have been removed from the data", ) + + +class DatasetTableTests(unittest.TestCase): + """Tests for DatasetTable and its subclasses""" + + def test_pandas_table_column_value_must_accept_all_string_variants(self): + """Ensure all the string dtypes ("str" and "string") + are guessed as a Khiops Text if the string is long enough + """ + # These strings lengths reach the threshold for a Khiops Text type + texts = ["x" * 101, "y" * 180] + for dtype in ("str", "string"): + dataframe = pd.DataFrame( + { + "message": pd.Series(texts, dtype=dtype), + } + ) + table = PandasTable("Table", dataframe) + variable = table.create_khiops_dictionary().get_variable("message") + self.assertEqual( + "Text", + variable.type, + msg=f"The string must be regarded as a Khiops Text", + )