-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: to_dict should return a native datetime object for NumPy backed dataframes #37571
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 13 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
af2f84d
BUG/REF: add native arg to maybe_box_datetimelike
arw2019 87265bc
BUG: pass native=True arg to maybe_box_datetimelike
arw2019 6b8221c
TST: add datetime column to test
arw2019 a28bfad
TST/CLN: test comments
arw2019 8821a8d
DOC: whatsnew
arw2019 717a6e3
CLN/TST: add bool test case & DRY the test
arw2019 ad78190
REF (feedback): move maybe_box_datetimelike common.py -> dtypes/cast.py
arw2019 c93fca9
feedback: remove native arg/accept Timestamp return type
arw2019 47fd80d
Merge remote-tracking branch 'upstream/master' into GH21256
arw2019 de86652
BUG: fix import in pd.core.indexes.interval.py
arw2019 b17a0db
BUG: fix import in pd.core.dtypes.cast.py
arw2019 1057c8a
BUG: revert accidental change tslib->tslibs
arw2019 5b2a84a
Merge remote-tracking branch 'upstream/master' into GH21256
arw2019 10119a7
REF (feedback): move dict_compat to core/dtypes/cast.py
arw2019 44d82c4
REF/TST: move dict_compat tests to dtypes/cast/test_dict_compat.py
arw2019 d737457
Merge remote-tracking branch 'upstream/master' into GH21256
arw2019 5d8d374
DOC: improve dict_compat doctring
arw2019 b9b8e31
DOC: add maybe_box_datetimelike docstring
arw2019 f1667f6
CLN: consolidate return in maybe_box_datetimelike
arw2019 5b984b8
TYP: maybe_box_datetimelike
arw2019 017fa58
TYP: maybe_box_datetimelike (return type)
arw2019 c76c09c
TYP: dict_compat
arw2019 2697b85
TST: remove dict_compat test from test_common.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
|
||
import numpy as np | ||
|
||
from pandas._libs import lib, tslib | ||
from pandas._libs import lib, tslib, tslibs | ||
from pandas._libs.tslibs import ( | ||
NaT, | ||
OutOfBoundsDatetime, | ||
|
@@ -134,6 +134,21 @@ def is_nested_object(obj) -> bool: | |
return False | ||
|
||
|
||
def maybe_box_datetimelike(value, dtype=None): | ||
# turn a datetime like into a Timestamp/timedelta as needed | ||
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 add a full-docstring, type if you can |
||
if dtype == object: | ||
# If we dont have datetime64/timedelta64 dtype, we dont want to | ||
# box datetimelike scalars | ||
return value | ||
|
||
if isinstance(value, (np.datetime64, datetime)): | ||
value = tslibs.Timestamp(value) | ||
elif isinstance(value, (np.timedelta64, timedelta)): | ||
value = tslibs.Timedelta(value) | ||
|
||
return value | ||
|
||
|
||
def maybe_downcast_to_dtype(result, dtype: Union[str, np.dtype]): | ||
""" | ||
try to cast to the specified dtype (e.g. convert back to bool/int | ||
|
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
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.
why don't you move dict_compat also to pandas/core/dtypes/cast.py (which uses maybe_box_datetimelike)