-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG/API: preserve non-nano in factorize/unique #51978
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 all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -1076,31 +1076,39 @@ def test_to_datetime_array_of_dt64s(self, cache, unit): | |
# Assuming all datetimes are in bounds, to_datetime() returns | ||
# an array that is equal to Timestamp() parsing | ||
result = to_datetime(dts, cache=cache) | ||
expected = DatetimeIndex([Timestamp(x).asm8 for x in dts], dtype="M8[ns]") | ||
if cache: | ||
# FIXME: behavior should not depend on cache | ||
expected = DatetimeIndex([Timestamp(x).asm8 for x in dts], dtype="M8[s]") | ||
else: | ||
expected = DatetimeIndex([Timestamp(x).asm8 for x in dts], dtype="M8[ns]") | ||
mroeschke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
tm.assert_index_equal(result, expected) | ||
|
||
# A list of datetimes where the last one is out of bounds | ||
dts_with_oob = dts + [np.datetime64("9999-01-01")] | ||
|
||
msg = "Out of bounds nanosecond timestamp: 9999-01-01 00:00:00" | ||
with pytest.raises(OutOfBoundsDatetime, match=msg): | ||
to_datetime(dts_with_oob, errors="raise") | ||
# As of GH#?? we do not raise in this case | ||
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. 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. have added this to my next CLN branch |
||
to_datetime(dts_with_oob, errors="raise") | ||
|
||
tm.assert_index_equal( | ||
to_datetime(dts_with_oob, errors="coerce", cache=cache), | ||
DatetimeIndex( | ||
result = to_datetime(dts_with_oob, errors="coerce", cache=cache) | ||
if not cache: | ||
# FIXME: shouldn't depend on cache! | ||
expected = DatetimeIndex( | ||
[Timestamp(dts_with_oob[0]).asm8, Timestamp(dts_with_oob[1]).asm8] * 30 | ||
+ [NaT], | ||
), | ||
) | ||
) | ||
else: | ||
expected = DatetimeIndex(np.array(dts_with_oob, dtype="M8[s]")) | ||
tm.assert_index_equal(result, expected) | ||
|
||
# With errors='ignore', out of bounds datetime64s | ||
# are converted to their .item(), which depending on the version of | ||
# numpy is either a python datetime.datetime or datetime.date | ||
tm.assert_index_equal( | ||
to_datetime(dts_with_oob, errors="ignore", cache=cache), | ||
Index(dts_with_oob), | ||
) | ||
result = to_datetime(dts_with_oob, errors="ignore", cache=cache) | ||
if not cache: | ||
# FIXME: shouldn't depend on cache! | ||
expected = Index(dts_with_oob) | ||
tm.assert_index_equal(result, expected) | ||
|
||
def test_out_of_bounds_errors_ignore(self): | ||
# https://github.com/pandas-dev/pandas/issues/50587 | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.