Skip to content

Commit c2f8d9f

Browse files
feature: add patching test result type checking (#2971)
* feature: add patching test result type checking * fix: add cpnp and dpctl check * fix: comments * fix: comments * fix: comments * fix: add transform test * fix: transform test * fix:comments * fix: versionb * feature: add dtype checking * fix: comments * Address review: predict dtype vs y, skip fp16 dtype check, forest apply exceptions * Add dtype check exceptions for KMeans predict and SVM estimators * Add ElasticNet/Lasso predict and path to _DTYPE_CHECK_SKIP in test_patching * Add more estimator-method pairs to _DTYPE_CHECK_SKIP Add LinearRegression, Ridge, IncrementalRidge, KNeighborsRegressor, ExtraTreesRegressor, RandomForestRegressor predict methods and LogisticRegression decision_function, KNeighborsClassifier predict_proba to dtype check skip set - these return float64 for integer/float32 inputs. * Add fitted attribute checks and automate dtype/type skip logic - Add _check_fitted_attributes() to verify fitted attributes preserve input array namespace and dtype (mirrors sklearn's new array API checks) - Automate regressor predict skip via is_regressor() - Automate clusterer predict/fit_predict skip via is_clusterer() - Automate SVM decision_function and fitted attr skips via BaseLibSVM - Automate tree apply skip via method name - Reduce hardcoded skip entries from ~70 to ~12 * Add missing fitted attr skip entries for CI failures * Add LogisticRegression.n_iter_ to FITTED_ATTR_NUMPY_OK * Remove n_iter_ from _INTEGER_FITTED_ATTRS (no-op, dtype check already skips non-float) * Add compat fallback for is_clusterer/is_regressor (sklearn < 1.6) * Add PCA.singular_values_ to FITTED_ATTR_NUMPY_OK * Add PCA.explained_variance_ratio_ to FITTED_ATTR_NUMPY_OK * Address reviewer feedback: use sklearn_check_version, update PCA comment - Replace try/except ImportError with sklearn_check_version('1.6') for is_clusterer/is_regressor imports - Keep PCA singular_values_ and explained_variance_ratio_ in skip set: array_api path produces correct types, but dpctl/dpnp path still returns numpy fitted attrs. Updated comment to clarify. * fix: use get_namespace instead of __sycl_usm_array_interface__ for device detection * fix: remove PCA fitted attrs from skip list - they preserve type correctly * fix: update comment for _FITTED_ATTR_NUMPY_OK_NON_NUMPY * fix: remove ElasticNet/Lasso/TSNE from skip list - now fall back to sklearn after #2996 * fix: use standard array API .device for device alignment check * fix: use standard .device in _check_fitted_attributes device check too * fix: stricter device and dtype checks per reviewer feedback - Device check: assert res has .device when X does (catches non-array output) - Device comparison: use direct == instead of str() - Dtype check: remove 'float in res.dtype' guard to catch wrong dtypes * fix: skip dtype check for sparse results (decision_path returns int64 indices) * fix: skip dtype check for integer structural outputs (decision_path n_nodes_ptr) * fix: add decision_path to dtype skip list instead of gating on res dtype decision_path returns (sparse_matrix, n_nodes_ptr) — n_nodes_ptr is inherently integer and should not match X's float dtype. * fix: simplify assert messages * fix: skip device check for attrs accepted as numpy in skip lists * fix: also skip device check on sklearn fallback * fix: use continue instead of flags for early exit, remove duplicate dtype skips * fix: add PCA fitted attrs back to skip list - numpy on dpnp/dpctl CPU path * feat: add sparse class checks for outputs and fitted attributes * fix: only skip NON_NUMPY attrs when array_api_dispatch is off, add sparse TODO * fix: remove PCA and IncrementalEmpiricalCovariance from output skip list after #3021 * fix: skip PCA.score_samples and covariance.mahalanobis output check when array_api_dispatch is off * fix: add IncrementalEmpiricalCovariance.mahalanobis to dtype skip list * fix: add output conversion to support_sycl_format, remove skip list support_sycl_format now converts output back to dpnp/dpctl matching support_input_format pattern. Removes _NUMPY_OUTPUT_OK_NO_DISPATCH skip list since PCA.score_samples and covariance.mahalanobis now return correct types. * Revert "fix: add output conversion to support_sycl_format, remove skip list" This reverts commit 46d1cce. * fix: enable array_api_dispatch for dpnp/dpctl output checks, skip dpctl linalg gaps * fix: address review - remove caplog.clear, move imports to top, update comments * fix: merge main, update sparse checks after #3029, move RF/ET classes_ to common skip list * fix: add missing get_namespace import * fix: replace hardcoded classes_ entries with programmatic check by attr name * fix: update comment for public fitted attr check * fix: check public attrs as starts with letter and ends with _ * fix: remove redundant classes_ entries from skip list * fix: update comments - SVM/clusterer attrs are skipped, not handled * fix: narrow SVM skip - check type on CPU, skip GPU/device/dtype * fix: update comments for skip lists and SVM checks * fix: use queue.sycl_device.is_gpu instead of string parsing for GPU check * fix: change caplog to INFO level, remove SVM GPU skip - fell_back now detects fallback * fix: remove probA_/probB_ from type skip - they are dpnp not numpy on CPU * fix: remove unused None defaults for est and method in _check_output_type * refactor: extract helper functions, rename skip lists for clarity * docs: shorten comments * docs: shorten output skip list comments * refactor: move imports to top, update docstring with call sequence * refactor: rename data_input to y for clarity * refactor: remove defensive result is None check * feat: add array_api output type check for pairwise_distances, restore est=None * docs: update _check_output_type docstring with type/device/dtype checks * fix: filter caplog records by sklearnex logger to avoid extra INFO messages * feat: add must-be-array check for fitted attrs like n_iter_, coef_ * fix: only skip classes_ type check when array_api_dispatch is off * fix: add allow_sklearn_fallback marker - pairwise_distances falls back for int dtypes * fix: revert to WARNING level, remove allow_sklearn_fallback, add SVM GPU skip back * docs: fix docstring - classes_ only skips without dispatch * fix: remove array_api from pairwise test - returns numpy on CI Python 3.13 * fix: skip second pass when estimator doesn't support GPU for this data, remove SVM GPU skip from _should_skip_all * docs: remove SVM GPU from docstring skip list * fix: rename helpers, merge main * fix: change _dpctl_has_linalg default to False * fix: simplify dpctl skip - always skip, linalg will never exist * fix: detect decision_path programmatically instead of listing each estimator * fix: remove regressor predict dtype skip - regressors preserve dtype * fix: skip regressor predict dtype only for integer inputs, not float * fix: skip regressor predict dtype for integer inputs only * fix: remove n_iter_ from must-be-array - scalar for KMeans per sklearn docs * fix: rename input_type to input_type_y for clarity * fix: remove _SCALAR_METHODS, rely on np.isscalar in loop * fix: remove 0-d array check - never triggered * fix: rename _INTEGER_FITTED_ATTRS to _DTYPE_SKIP_ATTRS * fix: remove _ATTR_SKIP_DTYPE_BY_NAME - redundant with is_clusterer/BaseLibSVM/classes_ inline checks * refactor: unify 7 skip lists into 1 dict + 1 set + 1 helper * fix: swap return order to result, X, y for conventional ordering * fix: revert pairwise result to _ - not used * fix: add LogisticRegression.classes_ to _SKIP - no array API support yet * fix: update dpctl skip message * feat: add pickle serialization check for dpnp/dpctl without dispatch * fix: remove defensive 0-d and isscalar checks from fitted attr filter - no estimator returns these * fix: add back isscalar check - some fitted attrs are scalars with dtype * fix: add KNeighborsClassifier.classes_ to _SKIP - numpy with dispatch on * fix: move pickle import to top, remove nosec - matches existing test patterns * fix: remove PCA no_dispatch entries - first pass doesn't check attrs * fix: simplify _should_skip - remove unused dispatch_on parameter * Update requirements-test.txt Co-authored-by: david-cortes-intel <david.cortes@intel.com> * fix: move pandas/polars imports back inline --------- Co-authored-by: david-cortes-intel <david.cortes@intel.com>
1 parent f0c875b commit c2f8d9f

3 files changed

Lines changed: 405 additions & 5 deletions

File tree

conda-recipe/meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ test:
9393
- treelite
9494
- array-api-compat
9595
- array-api-strict
96+
- polars
9697
source_files:
9798
- .ci
9899
- setup.cfg

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ treelite==4.7.0
1919
array-api-compat==1.14.0
2020
array-api-strict==2.3.1 ; python_version <= '3.11'
2121
array-api-strict==2.5 ; python_version >= '3.12'
22+
polars==1.39.3
2223
packaging==26.0

0 commit comments

Comments
 (0)