Skip to content

FEAT add pandas support - #552

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

adrinjalali wants to merge 12 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 Outdated
Comment thread skops/io/_pandas.py
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 Outdated
Comment thread docs/changes.rst Outdated
Comment thread docs/persistence.rst Outdated

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 Outdated

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 Outdated
Comment thread docs/changes.rst Outdated
Comment thread docs/persistence.rst Outdated

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
Comment thread docs/changes.rst Outdated
Comment thread docs/persistence.rst Outdated

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
Comment on lines +307 to +308
content = {"subtype": str(obj.subtype), "fill_value": obj.fill_value}
return _pandas_state(obj, "PandasSparseDtypeNode", content, save_context)

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