Repository: sktime/sktime
Issue category: Performance Issue

Issue:
[ENH] `polars` schema checks - address performance warnings
The current schema checks for lazy `polars` based data types raise performance warnings, e.g.,

```
sktime/datatypes/tests/test_check.py::test_check_metadata_inference[Table-polars_lazy_table-fixture:1]
  /home/runner/work/sktime/sktime/sktime/datatypes/_adapter/polars.py:234: PerformanceWarning: Determining the width of a LazyFrame requires resolving its schema, which is a potentially expensive operation. Use `LazyFrame.collect_schema().len()` to get the width without this warning.
    metadata["n_features"] = obj.width - len(index_cols)
```

These should be addressed.

The tests to execute to check whether these warnings persist are those in the `datatypes` module - these are automatically executed for a change in the impacted file, on remote CI.


Hints:

Patch:
diff --git a/sktime/datatypes/_adapter/polars.py b/sktime/datatypes/_adapter/polars.py
index e1fdd5f3ab7..e8138e4faa9 100644
--- a/sktime/datatypes/_adapter/polars.py
+++ b/sktime/datatypes/_adapter/polars.py
@@ -226,22 +226,31 @@ def check_polars_frame(
 
     # columns in polars are unique, no check required
 
+    if lazy:
+        width = obj.collect_schema().len()
+        columns = obj.collect_schema().names()
+        dtypes = obj.collect_schema().dtypes()
+    else:
+        width = obj.width
+        columns = obj.columns
+        dtypes = obj.dtypes
+
     if _req("is_empty", return_metadata):
-        metadata["is_empty"] = obj.width < 1
+        metadata["is_empty"] = width < 1
     if _req("is_univariate", return_metadata):
-        metadata["is_univariate"] = obj.width - len(index_cols) == 1
+        metadata["is_univariate"] = width - len(index_cols) == 1
     if _req("n_features", return_metadata):
-        metadata["n_features"] = obj.width - len(index_cols)
+        metadata["n_features"] = width - len(index_cols)
     if _req("feature_names", return_metadata):
-        feature_columns = [x for x in obj.columns if x not in index_cols]
+        feature_columns = [x for x in columns if x not in index_cols]
         metadata["feature_names"] = feature_columns
     if _req("dtypekind_dfip", return_metadata):
         index_cols_count = len(index_cols)
-        dtype_list = obj.dtypes[index_cols_count:]
+        dtype_list = dtypes[index_cols_count:]
         metadata["dtypekind_dfip"] = _polars_dtype_to_kind(dtype_list)
     if _req("feature_kind", return_metadata):
         index_cols_count = len(index_cols)
-        dtype_list = obj.dtypes[index_cols_count:]
+        dtype_list = dtypes[index_cols_count:]
         dtype_kind = _polars_dtype_to_kind(dtype_list)
         metadata["feature_kind"] = _get_feature_kind(dtype_kind)
 


Test patch: