Lazy imports for pandas, numpy and sklearn - #79
Conversation
The telemetry package only needs the light helpers (singleton, ttl_cache, shape_of) from utils.py, but the module-level pandas/numpy/sklearn imports forced every consumer of telemetry to install the full data stack. Defer those imports to the four dataset/CSV helper functions that actually use them, so API services can import telemetry without pandas installed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request refactors src/tabpfn_common_utils/utils.py to lazily import heavy dependencies like pandas, numpy, and scikit-learn. By using from __future__ import annotations and moving these imports inside the functions that require them (or within a TYPE_CHECKING block), the module can be imported in environments without the heavy data stack installed. There are no review comments, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
With utils.py importing them lazily, nothing in the default install path needs the data stack anymore. Consumers that use the dataset/array helpers (get_example_dataset, regression_pred_result, expense_estimation, ...) install `tabpfn-common-utils[datasets]`; ML consumers (tabpfn, tabpfn-client) already declare these packages directly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6a34615. Configure here.
This reverts commit 6a34615.
Co-authored-by: Oscar <oscar@priorlabs.ai>

Why
utils.pyimports pandas, numpy and scikit-learn at module level, but the telemetry package only needs its light helpers (singleton,ttl_cache,shape_of). This forces every consumer oftabpfn_common_utils.telemetry— including API services that never touch a DataFrame — to have the full data stack importable.What
Move the pandas/numpy/sklearn imports inside the four functions that actually use them (
serialize_to_csv_formatted_bytes,get_example_dataset,get_dataset_with_specific_size,assert_y_pred_proba_is_valid). Signatures are unchanged (from __future__ import annotations+TYPE_CHECKINGimports).Declared dependencies are deliberately NOT touched: every consumer keeps installing exactly what it does today. Slim consumers that install the package without its declared deps (e.g. gapi in tabpfn-server) can now import the telemetry modules safely; the heavy helpers raise
ImportErroronly when called without the stack installed.(Note: an intermediate commit moved numpy/pandas/scikit-learn to a
datasetsextra; it was reverted to keep install behavior unchanged for existing consumers.)Testing
import tabpfn_common_utils.telemetryand...utilssucceed with a meta-path hook that blocks pandas/numpy/sklearn/scipy.pytest(169 passed),ruff check,ruff format --check,pyright(0 errors) all clean.🤖 Generated with Claude Code