Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion khiops/sklearn/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def get_khiops_type(numpy_type, categorical_str_max_size=None):
# float<x>, int<x>, uint<x> 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:
Expand Down
26 changes: 25 additions & 1 deletion tests/test_dataset_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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",
)
Loading