Repository navigation
FEAT add pandas support - #552
adrinjalali wants to merge 17 commits into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Dtype reconstruction can invoke untrusted extension code, and some pandas state is not preserved correctly.
Review effort: Balanced
Findings: 1
Open (6)
Avoid global dtype registry when reconstructing trusted pandas dtypes · New Preserve MultiIndex sortorder during reconstruction · New Preserve StringDtype storage metadata during round-trip · New Add category_encoders to CI to run the regression test · New Document omitted array frequencies and DataFrame flags · New Document omitted array frequencies and DataFrame flags · New
What changed in this PR
Adds pandas persistence support to skops.io, including support for estimators such as TargetEncoder.
Changes:
- Adds pandas serializers, loaders, and trusted types.
- Adds round-trip, cross-version, and integration tests.
- Updates pandas dependencies and documentation.
| File | Description |
|---|---|
skops/io/_pandas.py |
Implements pandas persistence nodes. |
skops/io/_persist.py |
Registers pandas handlers lazily. |
skops/io/_trusted_types.py |
Trusts supported pandas types. |
skops/io/tests/test_pandas.py |
Adds pandas persistence tests. |
skops/io/tests/data/pandas-2.0.3.skops |
Adds pandas 2 compatibility fixture. |
skops/io/tests/data/pandas-3.0.3.skops |
Adds pandas 3 compatibility fixture. |
pyproject.toml |
Configures pandas test versions. |
pixi.lock |
Updates resolved dependencies. |
docs/requirements.txt |
Raises the pandas documentation minimum. |
docs/persistence.rst |
Documents pandas support. |
docs/changes.rst |
Adds the release note. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| def extension_dtype_get_state(obj: Any, save_context: SaveContext) -> dict[str, Any]: | ||
| # Extension dtypes are rebuilt from their string form, e.g. "Int64", | ||
| # "datetime64[ns, UTC]" or "period[M]". | ||
| content = {"name": str(obj)} |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved trust-validation mismatches and round-trip correctness issues prevent safe approval.
5 open issues
Reject file-backed zones with misleading timezone keys · New Validate loader constructors against declared module and class · New Normalize trusted class names to public type paths · New Respect declared array class for temporal NumPy dtypes · New Preserve StringDtype storage metadata during round-trip
1 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
The pandas test incorrectly requires identical array types, causing failures when pyarrow is installed but pandas defaults to Python string storage, despite the loader intentionally not preserving string storage.
2 open issues
3 resolved since last review
Review effort: Balanced
| dumps(obj) | ||
| # the string dtype with pyarrow storage is a string dtype, and supported | ||
| strings = pd.array(["a", None], dtype=pd.StringDtype("pyarrow")) | ||
| _assert_vals_equal(strings, _loads(dumps(strings))) |



This adds pandas support. Since the CI is testing enough versions after pandas v2, I'm confident this wouldn't give us too many headaches.
Fixes #450