-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Bugfix timedelta notimplemented eq #21394
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
jbrockmendel
merged 15 commits into
pandas-dev:master
from
Sup3rGeo:bugfix-timedelta-notimplemented-eq
Oct 24, 2018
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5d78297
Return NotImplemented for unknown types in comparison.
e656738
Added tests and updated whatsnew.
049dbe9
Removed excess space LINT
1e64ece
TST/BUG Always return NotImplemented. Updated tests to take into acco…
adec659
Line too long.
dd185e6
Fixed version_info call in test.
a6ccefd
Merge branch 'master' of https://github.com/pandas-dev/pandas into bu…
782568f
Moved changes to v0.24.0
ba307b4
Skipped test based on PY2
81648ed
Updated test names.
aa766f0
Removed unused import
d86c7ce
Merge remote-tracking branch 'upstream/master' into bugfix-timedelta-…
16c8222
Fixed whatsnew placement and commented test.
ab6384f
Merge branch 'master' of https://github.com/pandas-dev/pandas into bu…
301615e
Merge remote-tracking branch 'upstream/master' into bugfix-timedelta-…
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
""" test the scalar Timedelta """ | ||
import sys | ||
import pytest | ||
|
||
import numpy as np | ||
|
@@ -42,8 +43,10 @@ def test_ops_error_str(self): | |
with pytest.raises(TypeError): | ||
left + right | ||
|
||
with pytest.raises(TypeError): | ||
left > right | ||
# GH 20829: python 2 comparison naturally does not raise TypeError | ||
Sup3rGeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if sys.version_info >= (3, 0): | ||
with pytest.raises(TypeError): | ||
left > right | ||
|
||
assert not left == right | ||
assert left != right | ||
|
@@ -103,6 +106,54 @@ def test_compare_timedelta_ndarray(self): | |
expected = np.array([False, False]) | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
def test_custom_comparison_object(self): | ||
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. test_compare_custom_object |
||
# GH20829 | ||
Sup3rGeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
class CustomClass(object): | ||
|
||
def __init__(self, cmp_result=None): | ||
self.cmp_result = cmp_result | ||
|
||
def generic_result(self): | ||
if self.cmp_result is None: | ||
return NotImplemented | ||
else: | ||
return self.cmp_result | ||
|
||
def __eq__(self, other): | ||
return self.generic_result() | ||
|
||
def __gt__(self, other): | ||
return self.generic_result() | ||
|
||
t = Timedelta('1s') | ||
|
||
assert not (t == "string") | ||
assert not (t == 1) | ||
assert not (t == CustomClass()) | ||
assert not (t == CustomClass(cmp_result=False)) | ||
|
||
assert t < CustomClass(cmp_result=True) | ||
assert not (t < CustomClass(cmp_result=False)) | ||
|
||
assert t == CustomClass(cmp_result=True) | ||
|
||
@pytest.mark.parametrize("val", [ | ||
Sup3rGeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"string", 1]) | ||
def test_raise_comparisons_unknown_types(self, val): | ||
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. test_compare_unknown_type |
||
# GH20829 | ||
t = Timedelta('1s') | ||
if sys.version_info >= (3, 0): | ||
# python 2 does not raises TypeError for comparisons | ||
# of different types | ||
with pytest.raises(TypeError): | ||
t >= val | ||
with pytest.raises(TypeError): | ||
t > val | ||
with pytest.raises(TypeError): | ||
t <= val | ||
with pytest.raises(TypeError): | ||
t < val | ||
|
||
|
||
class TestTimedeltas(object): | ||
|
||
|
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.
move to 0.24