Skip to content

Conversation

@holdenk
Copy link
Contributor

@holdenk holdenk commented Feb 28, 2018

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
Copy link
Contributor Author

holdenk commented Feb 28, 2018

cc @aaltay

@holdenk
Copy link
Contributor Author

holdenk commented Mar 1, 2018

cc @robertwb

# pylint: enable=ungrouped-imports


@deprecated(since="v2.4")
Copy link
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
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
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.

Copy link

@cclauss cclauss Mar 2, 2018

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

Copy link

@cclauss cclauss Mar 2, 2018

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
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
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
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
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?

Copy link
Contributor Author

@holdenk holdenk Mar 2, 2018

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
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
Copy link
Member

aaltay commented Mar 3, 2018

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

holdenk commented Mar 5, 2018

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
Copy link
Contributor Author

holdenk commented Mar 7, 2018

ok cc @aaltay

Copy link

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

LGTM

@holdenk
Copy link
Contributor Author

holdenk commented Mar 13, 2018

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
Copy link
Member

aaltay commented Mar 13, 2018

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

holdenk commented Mar 14, 2018

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

@holdenk
Copy link
Contributor Author

holdenk commented Mar 14, 2018

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

@aaltay
Copy link
Member

aaltay commented Mar 15, 2018

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

@aaltay
Copy link
Member

aaltay commented Mar 15, 2018

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
Copy link
Contributor Author

holdenk commented Apr 2, 2018

CC @aaltay

@aaltay
Copy link
Member

aaltay commented Apr 3, 2018

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

@cclauss
Copy link

cclauss commented Apr 3, 2018

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

@aaltay
Copy link
Member

aaltay commented Apr 3, 2018

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

cgarciae commented Apr 4, 2018

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

@stale
Copy link

stale bot commented Jun 7, 2018

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
Copy link

stale bot commented Jun 14, 2018

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