Skip to content

BUG/CLN: clean-up get_values logic in objToJSON#65744

Merged
jorisvandenbossche merged 6 commits into
pandas-dev:mainfrom
jorisvandenbossche:obj-to-json-get_values-cleanup
Jun 26, 2026
Merged

BUG/CLN: clean-up get_values logic in objToJSON#65744
jorisvandenbossche merged 6 commits into
pandas-dev:mainfrom
jorisvandenbossche:obj-to-json-get_values-cleanup

Conversation

@jorisvandenbossche

Copy link
Copy Markdown
Member

Follow-up on #65127 (cc @Julian-Harbeck)

Cleans up that "get_values" logic to just rely on _values_from_json (except for MultiIndex). That removes the specific check for Index with tz to not go through .values.

In the end the code is not much shorter, but I think should be easier to follow (it's just first checking for MultiIndex, and in that case doing .values, and otherwise accessing obj.array._values_for_json(), with a bunch of error checking)

@jorisvandenbossche jorisvandenbossche added this to the 3.1 milestone May 28, 2026
@jorisvandenbossche jorisvandenbossche added IO JSON read_json, to_json, json_normalize Clean labels May 28, 2026

@Julian-Harbeck Julian-Harbeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. Do I understand it correctly that the tz special casing is not needed anymore since essentially we have replaced obj.values with obj._values_for_json which calls obj.__array__ under the hood, same as before in the special case?

@jorisvandenbossche

Copy link
Copy Markdown
Member Author

That is my understanding as well, yes

Comment thread pandas/_libs/src/vendored/ujson/python/objToJSON.c
Comment thread pandas/_libs/src/vendored/ujson/python/objToJSON.c
@jbrockmendel

Copy link
Copy Markdown
Member

I think this addresses the bugfix portion of #66007. Can you port the test and whatsnew from that

@jorisvandenbossche jorisvandenbossche changed the title CLN: clean-up get_values logic in objToJSON BUG/CLN: clean-up get_values logic in objToJSON Jun 26, 2026
@jorisvandenbossche

Copy link
Copy Markdown
Member Author

I think this addresses the bugfix portion of #66007. Can you port the test and whatsnew from that

Ah, good catch, those tests indeed pass now. Added

Comment thread doc/source/whatsnew/v3.1.0.rst Outdated
@jorisvandenbossche jorisvandenbossche merged commit 4e409ef into pandas-dev:main Jun 26, 2026
41 of 44 checks passed
@jorisvandenbossche jorisvandenbossche deleted the obj-to-json-get_values-cleanup branch June 26, 2026 22:21
hamdanal pushed a commit to hamdanal/pandas that referenced this pull request Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Clean IO JSON read_json, to_json, json_normalize

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants