BUG: Fix DataFrame.to_dict(orient='index', into=...) to apply into to nested mappings#66037
Closed
C1-BA-B1-F3 wants to merge 1 commit into
Closed
BUG: Fix DataFrame.to_dict(orient='index', into=...) to apply into to nested mappings#66037C1-BA-B1-F3 wants to merge 1 commit into
C1-BA-B1-F3 wants to merge 1 commit into
Conversation
… nested mappings - Fixed DataFrame.to_dict() with orient='index' to apply the 'into' parameter to nested row mappings, not just the outer mapping - Added test_to_dict_index_into_nested to verify the fix works for all code paths: * All object dtype columns (are_all_object_dtype_cols path) * Mixed dtypes (box_native_indices path) * Non-object dtypes (else path) * OrderedDict and defaultdict mappings - Closes pandas-dev#65778
Author
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.
Description
This PR fixes issue #65778 where
DataFrame.to_dict(orient="index", into=...)only applies theintoparameter to the outer mapping, not to the nested row mappings.Changes
Bug Fix
pandas/core/methods/to_dict.pyto apply theintoparameter to nested row mappings whenorient='index'are_all_object_dtype_colspath (all object dtype columns)box_native_indicespath (mixed dtypes with object columns)elsepath (non-object dtypes)Tests
test_to_dict_index_into_nestedtest inpandas/tests/frame/methods/test_to_dict.pyExample
Before the fix:
After the fix:
Testing
All tests pass:
pytest pandas/tests/frame/methods/test_to_dict.py::TestDataFrameToDict::test_to_dict_index_into_nested -xvsCloses #65778