Skip to content

FEAT add pandas support - #552

Open
adrinjalali wants to merge 17 commits into
skops-dev:mainfrom
adrinjalali:feat/pandas-persistence
Open

adrinjalali wants to merge 17 commits into
skops-dev:mainfrom
adrinjalali:feat/pandas-persistence

Conversation

@adrinjalali

Copy link
Copy Markdown
Member

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity · 3 Medium severity · 2 Low severity

Open (6)
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.

Comment thread skops/io/_pandas.py Resolved
Comment thread skops/io/_pandas.py Resolved
Comment thread skops/io/_pandas.py Outdated
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)}
Comment thread skops/io/tests/test_pandas.py Resolved
Comment thread docs/changes.rst Resolved
Comment thread docs/persistence.rst Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The new trusted deserialization surface and cross-version persistence format warrant final human security review.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
Resolved since last review (4)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Sub-minute fixed timezone offsets are silently corrupted during serialization.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (1)

Comment thread skops/io/_pandas.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Arrow-backed trusted types lack coverage, and the documentation overstates support for third-party extension types.

Review effort: Balanced
Findings: 2 Medium severity · 2 Low severity

Open (4)
Resolved since last review (1)

Comment thread skops/io/_trusted_types.py Resolved
Comment thread docs/changes.rst Resolved
Comment thread docs/persistence.rst Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread .github/workflows/build-test.yml Resolved
Comment thread docs/changes.rst Resolved
Comment thread docs/persistence.rst Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Valid SparseDtype objects with non-JSON fill values can be dumped but cannot be loaded.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (3)

Comment thread skops/io/_pandas.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread skops/io/_pandas.py Resolved
Comment thread skops/io/_pandas.py Resolved
Comment thread skops/io/_pandas.py Resolved
Comment thread skops/io/_pandas.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread skops/io/_pandas.py Resolved
Comment thread skops/io/_pandas.py Resolved
Comment thread skops/io/_pandas.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

skops can't load TargetEncoder object

2 participants