fix: wrap read_json args in StringIO for pandas 3.x compat - #477
Open
SudipSinha wants to merge 1 commit into
Open
fix: wrap read_json args in StringIO for pandas 3.x compat#477SudipSinha wants to merge 1 commit into
SudipSinha wants to merge 1 commit into
Conversation
pandas 3.x no longer accepts a raw JSON string as the path_or_buf argument to pd.read_json — it treats all strings as file paths, raising FileNotFoundError when the string is inline JSON. Wrapping with io.StringIO passes a file-like object instead, which works across pandas 2.x and 3.x. Fixes 13 failing tests in TestSerializationCounterfactualExplanations, TestDiceKDRegressionMethods, and TestDiceRandomRegressionMethods. Signed-off-by: Sudip Sinha <sudip.sinha@redhat.com> Signed-off-by: Sudip Sinha <Sudip.Sinha@RedHat.com> rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED
Author
|
Fixes #422 (pandas 3.x support). |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pandas 3.x removed support for passing a raw JSON string directly to
pd.read_json. It now treats all strings as file paths, raisingFileNotFoundErrorwhen the string is inline JSON:Fix: wrap the JSON string in
io.StringIOto pass a file-like object instead. Works on pandas 2.x and 3.x.File:
dice_ml/diverse_counterfactuals.py—CounterfactualExamples.from_json(2 call sites at lines 226 and 229)Impact
Fixes 13 failing tests across
TestSerializationCounterfactualExplanations,TestDiceKDRegressionMethods, andTestDiceRandomRegressionMethods. No change in parsed output —StringIOonly changes the I/O path, not the parsing.Test plan
TestSerializationCounterfactualExplanationstests now passTestDiceKDRegressionMethodsdeserialization tests now passTestDiceRandomRegressionMethods::test_random_output(sklearn backend) now passTested on Python 3.12, 3.13, 3.14 with pandas 3.0.5.