Skip to content

Commit eb49a56

Browse files
fix: use PY311 models for Python 3.12+ to fix monotonic_cst AttributeError
predictor.py hardcoded version checks for [9, 10, 11], causing Python 3.12 and 3.13 to fall through to the root-level pkl files which were serialized with an old sklearn (<1.4) that lacks the monotonic_cst attribute. Fix: clamp to the newest versioned directory (PY311) for any unknown minor version. sklearn is pinned at >=1.6.1,<2.0 for all Python versions, so the PY311 models (re-serialized in the uv migration, #113) are pickle-compatible with Python 3.12 and 3.13. Fixes: AttributeError: 'DecisionTreeClassifier' object has no attribute 'monotonic_cst'
1 parent 6ccd644 commit eb49a56

1 file changed

Lines changed: 12 additions & 17 deletions

File tree

sapientml_core/seeding/predictor.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -267,23 +267,18 @@ def predict(task: Task, dataset_summary: DatasetSummary) -> PipelineSkeleton:
267267
# check python version and store as a variable
268268
python_minor_version = sys.version_info.minor
269269

270-
# Load all the pkl files based on python version
271-
if python_minor_version in [9, 10, 11]:
272-
base_path = Path(os.path.dirname(__file__)) / ("../models/PY3" + str(python_minor_version))
273-
with open(base_path / "pp_models.pkl", "rb") as f:
274-
pp_model = pickle.load(f)
275-
276-
with open(base_path / "mp_model_1.pkl", "rb") as f1:
277-
with open(base_path / "mp_model_2.pkl", "rb") as f2:
278-
m_model = (pickle.load(f1), pickle.load(f2))
279-
280-
else: # Default
281-
with open(Path(os.path.dirname(__file__)) / "../models/pp_models.pkl", "rb") as f:
282-
pp_model = pickle.load(f)
283-
284-
with open(Path(os.path.dirname(__file__)) / "../models/mp_model_1.pkl", "rb") as f1:
285-
with open(Path(os.path.dirname(__file__)) / "../models/mp_model_2.pkl", "rb") as f2:
286-
m_model = (pickle.load(f1), pickle.load(f2))
270+
# Load all the pkl files based on python version.
271+
# For Python versions beyond the newest versioned directory, use the newest
272+
# available models (sklearn version is pinned, so pkl is cross-version compatible).
273+
_versioned = [9, 10, 11]
274+
version_key = python_minor_version if python_minor_version in _versioned else max(_versioned)
275+
base_path = Path(os.path.dirname(__file__)) / f"../models/PY3{version_key}"
276+
with open(base_path / "pp_models.pkl", "rb") as f:
277+
pp_model = pickle.load(f)
278+
279+
with open(base_path / "mp_model_1.pkl", "rb") as f1:
280+
with open(base_path / "mp_model_2.pkl", "rb") as f2:
281+
m_model = (pickle.load(f1), pickle.load(f2))
287282
preprocessor_labels = _predict_preprocessors(pp_model, p_meta_feature_test, search_space.target_labels)
288283
all_labels = _predict_models(m_model, task_type, m_meta_feature_test, preprocessor_labels)
289284

0 commit comments

Comments
 (0)