-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Bugfix timedelta notimplemented eq #21394
Bugfix timedelta notimplemented eq #21394
Conversation
@jbrockmendel following up from the issue discussion, the tests look good it seems? Except for python 2 that actually has different ordering behavior than python 3, this is why it it fails on python2: What do you think? Could we just then add a special case checking for python 2 that raises TypeError? |
Seems reasonable. What other tests are affected? This may be a good opportunity to flesh them out. |
…unt that python 2 does not raise TypeError for uncompatible types.
Hello @Sup3rGeo! Thanks for updating the PR.
Comment last updated on October 23, 2018 at 19:08 Hours UTC |
Codecov Report
@@ Coverage Diff @@
## master #21394 +/- ##
=======================================
Coverage 92.22% 92.22%
=======================================
Files 169 169
Lines 50897 50897
=======================================
Hits 46940 46940
Misses 3957 3957
Continue to review full report at Codecov.
|
I gave it a second thought and I think we should not have a special case for python 2 because if we raise manually from the So this last commit is only testing for |
Take a look at the Travis log; the test is raising before getting to the behavior you care about. In nearly all cases we want the behavior to be identical in py2 and py3. Is there a compelling reason to break that rule in this case? |
Basically the comparisons are implemented differently in python 2 and python 3, so with the changes in this PR we are just following python itself. Which I believe is good for the following reasons:
The way |
I'd argue that the default python2 behavior is itself surprising. Having |
I agree with you about python 2 having this surprising behavior, and that it would be desirable to have them work the same. Its just that given that our current implementation also brings undesired side-effects, if we have to choose between two evils, I would say it is better to just expose these intrinsic python2-3 differences to the user. IMHO it breaks less "contracts" (and then surely this python2-3 differences aren't to blame pandas, but something users naturally have to deal with when working with different backward-incompatible python versions, just like the different strings behavior and so on). Well we might not 100% agree on this but thanks for the support so far @jbrockmendel. Let's see what @jreback thinks. |
IIRC there is a bug in the cpython impl for comparisons with timedelta in py2, maybe @cpcloud remembers where it actually is. |
doc/source/whatsnew/v0.23.1.txt
Outdated
@@ -59,6 +59,7 @@ Data-type specific | |||
|
|||
- Bug in :meth:`Series.str.replace()` where the method throws `TypeError` on Python 3.5.2 (:issue: `21078`) | |||
- Bug in :class:`Timedelta`: where passing a float with a unit would prematurely round the float precision (:issue: `14156`) | |||
- Bug in :class:`Timedelta`: Comparison with unknown types now return NotImplemented as typically expected (:issue: `20829`) |
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
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
test_compare_custom_object
|
||
@pytest.mark.parametrize("val", [ | ||
"string", 1]) | ||
def test_raise_comparisons_unknown_types(self, val): |
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.
test_compare_unknown_type
so I think something broke as the circle tests are failing. needs to very carefully look at all failures as this is a far reaching change. |
…gfix-timedelta-notimplemented-eq
I will further investigate the errors. |
I might need some help to debug the failing test on CircleCI. Any idea how can I reproduce it locally on my machine? |
can you rebase / update |
…notimplemented-eq # Conflicts: # doc/source/whatsnew/v0.24.0.txt # pandas/_libs/tslibs/timedeltas.pyx
I tried installing ubuntu in a virtual machine and running the same scripts the the failing CircleCI build, and the failing test is still passing. |
this looks fine. can you rebase. ping on green. |
…gfix-timedelta-notimplemented-eq
@jreback sorry what do you mean by "ping on green"? |
@Sup3rGeo when all the CI checks have green checkmarks (as opposed to red "x"s) write a comment "ping" to get his attention |
@jreback, @jbrockmendel I think I am in a dead end because I cannot manage to reproduce this failure locally. I would need some help/pointers here. |
merge master and push again |
…notimplemented-eq
Oh, seems like it's green now. |
@jbrockmendel if you'd have a look. merge when satisified. |
LGTM. Thanks @Sup3rGeo |
@@ -193,6 +193,7 @@ Other Enhancements | |||
- :func:`~DataFrame.to_csv`, :func:`~Series.to_csv`, :func:`~DataFrame.to_json`, and :func:`~Series.to_json` now support ``compression='infer'`` to infer compression based on filename extension (:issue:`15008`). | |||
The default compression for ``to_csv``, ``to_json``, and ``to_pickle`` methods has been updated to ``'infer'`` (:issue:`22004`). | |||
- :func:`to_timedelta` now supports iso-formated timedelta strings (:issue:`21877`) | |||
- Comparing :class:`Timedelta` with unknown types now return ``NotImplemented`` instead of ``False`` (:issue:`20829`) |
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.
NotImplemented -> raises a TypeError (that is what the user sees)
Fixed in #23355
* Return NotImplemented for unknown types in comparison. * Added tests and updated whatsnew. * Removed excess space LINT * TST/BUG Always return NotImplemented. Updated tests to take into account that python 2 does not raise TypeError for uncompatible types. * Line too long. * Fixed version_info call in test. * Moved changes to v0.24.0 * Skipped test based on PY2 * Updated test names. * Removed unused import * Fixed whatsnew placement and commented test.
* Revert pandas-dev#21394 * Typo fixup
* Return NotImplemented for unknown types in comparison. * Added tests and updated whatsnew. * Removed excess space LINT * TST/BUG Always return NotImplemented. Updated tests to take into account that python 2 does not raise TypeError for uncompatible types. * Line too long. * Fixed version_info call in test. * Moved changes to v0.24.0 * Skipped test based on PY2 * Updated test names. * Removed unused import * Fixed whatsnew placement and commented test.
* Revert pandas-dev#21394 * Typo fixup
git diff upstream/master -u -- "*.py" | flake8 --diff