-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Series.to_dict does not return native Python types #37648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 24 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
a2e3e55
TST: add GH25969 OP
arw2019 41f0a4b
ENH: add maybe_box_native
arw2019 5e4edbe
ENH: use maybe_box_native in Series.to_dict
arw2019 b6967b7
BUG: add scalar check to maybe_box_native
arw2019 55919e0
BUG: suppress int conversion ValueError in maybe_box_native
arw2019 759e091
TST: rewrite existing to_dict tests
arw2019 6f966f2
CLN: use maybe_box_datetimelike -> maybe_box_native in DataFrame.to_dict
arw2019 1e058ab
Merge remote-tracking branch 'upstream/master' into maybe_box_native
arw2019 2ebd673
TYP: maybe_box_native
arw2019 1dc5935
DOC: add docstring to maybe_box_native
arw2019 1e5e459
DOC: whatsnew
arw2019 3c6bd7e
TYP: fix input type hint in maybe_box_native
arw2019 e3cc18f
TST (feedback): add uint testcases
arw2019 22819b7
TST (feedback): add uint testcases
arw2019 fb782df
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 cb389d9
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 249968e
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 1f5d442
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 9686035
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 732fb84
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 ec6cbfc
merge master + move to 1.3
arw2019 4bb1916
fixups
arw2019 587e592
fix merge error
arw2019 9d81f54
whatsnew
arw2019 673da4e
fix typing
arw2019 ef639c9
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 4036b63
tests
arw2019 89a841d
add NumericArray path in to_numeric
arw2019 68420ea
review: tests
arw2019 8b83e24
add bool check
arw2019 86b0e04
review: maybe_box_native takes Scalar arg only
arw2019 efc95b8
merge master
arw2019 c3b723a
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 d5a9476
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 3e2ea12
review comments: add unit test
arw2019 a455fcc
CI failures
arw2019 5541a35
merge master
arw2019 fcbf705
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 9282ca3
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 a444ef5
silence NumPy deprecation warning (np.int -> int)
arw2019 2411a70
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 99d7c55
silence NumPy deprecation warning (np.float -> float)
arw2019 e009a9e
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 eaeb409
whatsnew
arw2019 a642a6b
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 0467e1b
review: use is_foo instead of is_foo_dtype
arw2019 5605bbd
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 39ca508
review: remove suppress in int clause to check if anything fails
arw2019 7fa7503
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 08567b4
pre-commit failure
arw2019 7c47df2
merge master
arw2019 618f8ef
merge master
arw2019 da620f2
review: more examples in unit test
arw2019 761b728
skip json test with numpy_dev
arw2019 49acd25
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 86c6aa7
revert changes to JSON test
arw2019 4650131
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
arw2019 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,31 +256,43 @@ def test_to_dict_wide(self): | |
expected = {f"A_{i:d}": i for i in range(256)} | ||
assert result == expected | ||
|
||
def test_to_dict_orient_dtype(self): | ||
# GH22620 & GH21256 | ||
|
||
df = DataFrame( | ||
{ | ||
"bool": [True, True, False], | ||
"datetime": [ | ||
@pytest.mark.parametrize( | ||
"data,dtype", | ||
( | ||
([True, True, False], bool), | ||
[ | ||
[ | ||
datetime(2018, 1, 1), | ||
datetime(2019, 2, 2), | ||
datetime(2020, 3, 3), | ||
], | ||
"float": [1.0, 2.0, 3.0], | ||
"int": [1, 2, 3], | ||
"str": ["X", "Y", "Z"], | ||
} | ||
) | ||
Timestamp, | ||
], | ||
[[1.0, 2.0, 3.0], float], | ||
[[1, 2, 3], int], | ||
[["X", "Y", "Z"], str], | ||
), | ||
) | ||
def test_to_dict_orient_dtype(self, data, dtype): | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# GH22620 & GH21256 | ||
|
||
expected = { | ||
"int": int, | ||
"float": float, | ||
"str": str, | ||
"datetime": Timestamp, | ||
"bool": bool, | ||
} | ||
df = DataFrame({"a": data}) | ||
d = df.to_dict(orient="records") | ||
assert all(type(record["a"]) is dtype for record in d) | ||
|
||
@pytest.mark.parametrize( | ||
"data,dtype", | ||
( | ||
[np.uint64(2), int], | ||
[np.int64(-9), int], | ||
[np.float64(1.1), float], | ||
[np.bool_(True), bool], | ||
[np.datetime64("2005-02-25"), Timestamp], | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
), | ||
) | ||
def test_to_dict_scalar_constructor_orient_dtype(self, data, dtype): | ||
# GH22620 & GH21256 | ||
|
||
for df_dict in df.to_dict("records"): | ||
result = {col: type(df_dict[col]) for col in list(df.columns)} | ||
assert result == expected | ||
df = DataFrame({"a": data}, index=[0]) | ||
d = df.to_dict(orient="records") | ||
assert type(d[0]["a"]) is dtype | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you break this out a bit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is no longer true rigth (e.g. this is not fixed in this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i'll get rid of this