Skip to content

[BEAM-3761]Fix Python 3 cmp usage#4774

Closed
holdenk wants to merge 9 commits into
apache:masterfrom
holdenk:BEAM-3761-fix-py3-missing-functions
Closed

[BEAM-3761]Fix Python 3 cmp usage#4774
holdenk wants to merge 9 commits into
apache:masterfrom
holdenk:BEAM-3761-fix-py3-missing-functions

Conversation

@holdenk

@holdenk holdenk commented Feb 28, 2018

Copy link
Copy Markdown
Contributor

Fixes our usage of cmp as part of Python 3 port. In some places where cmp was not being used remove the function entirely, in others rewrite to use total_ordering annotation.


Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue.
  • [X ] Write a pull request description that is detailed enough to understand:
    • [ X] What the pull request does
    • [ X ] Why it does it
    • [ X ] How it does it
    • [ X ] Why this approach
  • [ X ] Each commit in the pull request should have a meaningful subject line and body.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will be performed on your pull request automatically. (ran python tests instead)
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

@holdenk

holdenk commented Feb 28, 2018

Copy link
Copy Markdown
Contributor Author

cc @aaltay

@holdenk

holdenk commented Mar 1, 2018

Copy link
Copy Markdown
Contributor Author

cc @robertwb

# pylint: enable=ungrouped-imports


@deprecated(since="v2.4")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we deprecating these functions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So they encourage cmp like behaviour and I didn't see them used internally. This is as a separate commit, I can keep them non-deprecated and just use the rewrite for the internal cmp usage.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

They are in the public API surface, it may have users. Let's not deprecate.

@cclauss cclauss Mar 2, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For the counterargument see What's new in Python 3: The cmp() function should be treated as gone, and the __cmp__() special method is no longer supported.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do not follow the counterargument. These two are static functions for comparing datastore keys and paths. Providing these functions should be orthogonal to having cmp functions in the language or not. We can deprecate this if we think that they do not provide value to users, but the decision should not depend on the availability of cmp.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can avoid deprecating them for now and revisit it later.

return (type(self) is type(other) and
self.timestamped_values == other.timestamped_values)

def __ne__(self, other):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you need to implement ne, is not this the default implementation?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@holdenk what do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In Python3 we are fine but in Python 2.7, ne isn't inherited from object. If you see the docs for total_ordering. See the notes in https://bugs.python.org/issue25732

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you.


from abc import ABCMeta
from abc import abstractmethod
from functools import total_ordering

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@charlesccychen

Where do we compare these events?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ping?

def __ne__(self, other):
return not self.__eq__(other)

def __lt__(self, other):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think a type mismatch should return NotImplemented here, or raise an error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds reasonable, I'll try that.


def __eq__(self, other):
return self.start == other.start and self.end == other.end
return type(self) == type(other) and \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same comment about type mismatch.

@cclauss cclauss Mar 2, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we put the whole test in parens and avoid backslash line termination as recommended in PEP8? The problem with backslash line termination is that a whitespace character to the right of the backslash breaks the script but is invisible to the reader.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

def __eq__(self, other):
return self.value == other.value and self.timestamp == other.timestamp

def __hash_(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you need to implement this? Also there is a typo in the name __hash_.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I guess its not needed then :) I'll remove it.

"""
if type(left) is not type(right):
return cmp(type(left), type(right))
return 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a change in behaviour even though it matches the comment above. What does this affect?

@holdenk holdenk Mar 2, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

All of the tests pass. If you were to sort a windowed value with something which was not a windowed value the ordering could change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good.

cc: @robertwb since this pertains to the todo below.

@aaltay

aaltay commented Mar 3, 2018

Copy link
Copy Markdown
Member

@holdenk Is this ready to review again? Github comment threading is confusing, I cannot always tell if all comments received a response or not.

@holdenk

holdenk commented Mar 5, 2018

Copy link
Copy Markdown
Contributor Author

I need to fix the multi-line ''s I think. I'm busy dealing with some internal company stuff (it turns out I like getting paid) and this week is Strata SJ so I'll try and update this Tuesday night.

@holdenk

holdenk commented Mar 7, 2018

Copy link
Copy Markdown
Contributor Author

ok cc @aaltay

@cclauss cclauss left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@holdenk

holdenk commented Mar 13, 2018

Copy link
Copy Markdown
Contributor Author

cc @aaltay & @robertwb

@holdenk holdenk force-pushed the BEAM-3761-fix-py3-missing-functions branch from 8d36869 to 89f757a Compare March 13, 2018 18:51
@aaltay

aaltay commented Mar 13, 2018

Copy link
Copy Markdown
Member

@holdenk I still see that datastore helper methods are being deprecated. I thought we decided not to do that. Also there is an open question to you in test_stream.py. Could you address those?

@holdenk

holdenk commented Mar 14, 2018

Copy link
Copy Markdown
Contributor Author

So the open "test_stream" issue, you pinged someone else on it for comment? Or is there another one?

@holdenk

holdenk commented Mar 14, 2018

Copy link
Copy Markdown
Contributor Author

Removed the deprecation as well, sorry about that. cc @aaltay

@aaltay

aaltay commented Mar 15, 2018

Copy link
Copy Markdown
Member

I can merge it once tests are green. For some reason, tests were not completed yet after a day.

@aaltay

aaltay commented Mar 15, 2018

Copy link
Copy Markdown
Member

retest this please

@holdenk holdenk force-pushed the BEAM-3761-fix-py3-missing-functions branch from 43b9c66 to cd98dae Compare April 2, 2018 20:16
@holdenk

holdenk commented Apr 2, 2018

Copy link
Copy Markdown
Contributor Author

CC @aaltay

@aaltay

aaltay commented Apr 3, 2018

Copy link
Copy Markdown
Member

@holdenk do you know why tests are failing before we merge?

@cclauss

cclauss commented Apr 3, 2018

Copy link
Copy Markdown

There seems to be a failure installing cython==0.26.1... The current cython on PyPI is 0.28.1

@aaltay

aaltay commented Apr 3, 2018

Copy link
Copy Markdown
Member

@cclauss perhaps it is a flake with installation? 0.26.1 is also available on pypi even though it is not the latest version.

@cgarciae

cgarciae commented Apr 4, 2018

Copy link
Copy Markdown

Also getting this error :(
I am reverting to python 2 for this but hope it gets fixed soon.

@stale

stale Bot commented Jun 7, 2018

Copy link
Copy Markdown

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@beam.apache.org list. Thank you for your contributions.

@stale stale Bot added the wontfix label Jun 7, 2018
@stale

stale Bot commented Jun 14, 2018

Copy link
Copy Markdown

This pull request has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@stale stale Bot closed this Jun 14, 2018
@kennknowles kennknowles added stale and removed wontfix labels Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants