Skip to content

fix(pydeck): Support pandas 3.x compatibility#9988

Merged
chrisgervang merged 2 commits intomasterfrom
chr/pydeck-pandas3-compat
Feb 6, 2026
Merged

fix(pydeck): Support pandas 3.x compatibility#9988
chrisgervang merged 2 commits intomasterfrom
chr/pydeck-pandas3-compat

Conversation

@chrisgervang
Copy link
Collaborator

@chrisgervang chrisgervang commented Feb 6, 2026

Closes #9986

Background

pydeck fails with pandas 3.x when calling .to_json() due to two issues:

  1. DataFrame detection uses module path checking that fails in pandas 3.x
  2. JSON serialization crashes on objects without __dict__ attribute

Change List

  • Replace module-based DataFrame detection in is_pandas_df() with duck-typing approach that works with both pandas 2.x and 3.x
  • Add defensive error handling in default_serialize() to handle objects without __dict__
  • Add tests for negative cases and duck-typing validation

Note

Low Risk
Behavior changes are localized to DataFrame detection and JSON fallback serialization, with low risk of broader impact beyond how some objects are classified/serialized.

Overview
Fixes pandas 3.x compatibility issues in pydeck by switching is_pandas_df() from module-path checks to a duck-typed DataFrame check (name + required methods), reducing false negatives across pandas versions.

Hardens JSON rendering in default_serialize() by safely handling objects without a __dict__: it now falls back to to_dict(orient="records") when available (e.g., DataFrames) and otherwise stringifies the object instead of raising. Adds tests covering negative is_pandas_df cases and validating the duck-typing behavior.

Written by Cursor Bugbot for commit df07e92. This will update automatically on new commits. Configure here.

… 2.x

Replace module-based DataFrame detection with duck-typing to work with both pandas 2.x and 3.x module paths. Add defensive error handling in JSON serialization to prevent crashes from objects without __dict__. Includes additional tests for edge cases.

Fixes #9986

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coveralls
Copy link

coveralls commented Feb 6, 2026

Coverage Status

coverage: 91.091%. remained the same
when pulling df07e92 on chr/pydeck-pandas3-compat
into a241b63 on master.

@chrisgervang chrisgervang requested a review from ibgreen February 6, 2026 06:32
Copy link
Collaborator

@ajduberstein ajduberstein left a comment

Choose a reason for hiding this comment

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

Thank you!

@chrisgervang
Copy link
Collaborator Author

Screenshot 2026-02-06 at 8 05 29 AM

Ran the scatterplot example with pandas 2 and 3, got the same result.

@chrisgervang chrisgervang merged commit b830b0e into master Feb 6, 2026
6 checks passed
@chrisgervang chrisgervang deleted the chr/pydeck-pandas3-compat branch February 6, 2026 16:08
felixpalmer pushed a commit that referenced this pull request Feb 10, 2026
… 2.x (#9988)

Replace module-based DataFrame detection with duck-typing to work with both pandas 2.x and 3.x module paths. Add defensive error handling in JSON serialization to prevent crashes from objects without __dict__. Includes additional tests for edge cases.

Fixes #9986

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@stonebig
Copy link

Didn't you forget to upload pydeck-9.2.7 to Pypi ? or is it waiting further testing ?

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.

[Bug] pydeck breaks streamlit with pandas 3

5 participants