Skip to content
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

Merged

Conversation

Sup3rGeo
Copy link
Contributor

@Sup3rGeo Sup3rGeo commented Jun 8, 2018

@gfyoung gfyoung added Bug Timedelta Timedelta data type labels Jun 8, 2018
@Sup3rGeo
Copy link
Contributor Author

Sup3rGeo commented Jun 9, 2018

@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:
https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
http://portingguide.readthedocs.io/en/latest/comparisons.html

What do you think? Could we just then add a special case checking for python 2 that raises TypeError?

@jbrockmendel
Copy link
Member

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.
@pep8speaks
Copy link

pep8speaks commented Jun 9, 2018

Hello @Sup3rGeo! Thanks for updating the PR.

Line 109:80: E501 line too long (81 > 79 characters)

Comment last updated on October 23, 2018 at 19:08 Hours UTC

@codecov
Copy link

codecov bot commented Jun 9, 2018

Codecov Report

Merging #21394 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #21394   +/-   ##
=======================================
  Coverage   92.22%   92.22%           
=======================================
  Files         169      169           
  Lines       50897    50897           
=======================================
  Hits        46940    46940           
  Misses       3957     3957
Flag Coverage Δ
#multiple 90.65% <ø> (ø) ⬆️
#single 42.29% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a0c91e...301615e. Read the comment docs.

@Sup3rGeo
Copy link
Contributor Author

Sup3rGeo commented Jun 9, 2018

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 __richcmp__ function than we still won't allow the other object to try to implement the comparison.

So this last commit is only testing for TypeErrors for python 3, letting python 2 comparisons (lt gt le ge) act as it is the default (not raising anything).

@jbrockmendel
Copy link
Member

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?

@Sup3rGeo
Copy link
Contributor Author

Sup3rGeo commented Jun 9, 2018

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:

  • pandas.Timedelta won't try to change the default python behavior on comparisons, so no surprises.
  • We don't break the ability of the other member of the comparison to implement it in a meaningful way (very important)

The way pandas.Timedelta is currently implemented in the released versions breaks item 2 because it does not follow item 1.

@jbrockmendel
Copy link
Member

won't try to change the default python behavior on comparisons, so no surprises.

I'd argue that the default python2 behavior is itself surprising. Having pd.Timedelta behave differently in py2 vs py3 seems very undesirable. That said, it's not me you need to convince, it's @jreback.

@Sup3rGeo
Copy link
Contributor Author

Sup3rGeo commented Jun 10, 2018

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.

@jreback
Copy link
Contributor

jreback commented Jun 13, 2018

IIRC there is a bug in the cpython impl for comparisons with timedelta in py2, maybe @cpcloud remembers where it actually is.

@@ -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`)
Copy link
Contributor

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):
Copy link
Contributor

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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_compare_unknown_type

@jreback
Copy link
Contributor

jreback commented Jun 13, 2018

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.

@Sup3rGeo
Copy link
Contributor Author

Sup3rGeo commented Jul 1, 2018

I will further investigate the errors.

@Sup3rGeo
Copy link
Contributor Author

Sup3rGeo commented Jul 1, 2018

I might need some help to debug the failing test on CircleCI. Any idea how can I reproduce it locally on my machine?

@jreback
Copy link
Contributor

jreback commented Sep 25, 2018

can you rebase / update

…notimplemented-eq

# Conflicts:
#	doc/source/whatsnew/v0.24.0.txt
#	pandas/_libs/tslibs/timedeltas.pyx
doc/source/whatsnew/v0.24.0.txt Outdated Show resolved Hide resolved
pandas/tests/scalar/timedelta/test_timedelta.py Outdated Show resolved Hide resolved
@Sup3rGeo
Copy link
Contributor Author

Sup3rGeo commented Oct 8, 2018

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.

@jreback jreback added this to the 0.24.0 milestone Oct 10, 2018
@jreback
Copy link
Contributor

jreback commented Oct 10, 2018

this looks fine. can you rebase. ping on green.

@Sup3rGeo
Copy link
Contributor Author

@jreback sorry what do you mean by "ping on green"?

@jbrockmendel
Copy link
Member

@Sup3rGeo when all the CI checks have green checkmarks (as opposed to red "x"s) write a comment "ping" to get his attention

@Sup3rGeo
Copy link
Contributor Author

@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.

@jreback
Copy link
Contributor

jreback commented Oct 23, 2018

merge master and push again

@Sup3rGeo
Copy link
Contributor Author

Oh, seems like it's green now.

@jreback
Copy link
Contributor

jreback commented Oct 24, 2018

@jbrockmendel if you'd have a look. merge when satisified.

@jbrockmendel
Copy link
Member

LGTM. Thanks @Sup3rGeo

@jbrockmendel jbrockmendel merged commit 5dd4cae into pandas-dev:master Oct 24, 2018
@Sup3rGeo Sup3rGeo deleted the bugfix-timedelta-notimplemented-eq branch October 24, 2018 16:43
@@ -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`)
Copy link
Member

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

tm9k1 pushed a commit to tm9k1/pandas that referenced this pull request Nov 19, 2018
* 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.
@jbrockmendel jbrockmendel mentioned this pull request Dec 4, 2018
jbrockmendel added a commit to jbrockmendel/pandas that referenced this pull request Dec 15, 2018
jreback pushed a commit that referenced this pull request Dec 15, 2018
* Revert #21394

* Typo fixup
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
* 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.
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timedelta always returning False for equality tests for incompatible types
6 participants