Skip to content

Add pythonic aliases for comparison predicates. #553

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org/).

### v0.17.7
* Add pythonic aliases for comparison predicates.
* Add alias tests to test_predicates.py
Copy link
Member

Choose a reason for hiding this comment

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

We don't need this line. Just the first one is fine :)


### v0.17.6
* Removed a deprecated function which allowed calling non-table attributes on a table.
* Removed a deprecated function which created an empty table.
Expand Down
43 changes: 43 additions & 0 deletions datascience/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,49 @@ def not_containing(substring):
def not_contained_in(superstring):
"""A string that is not contained within the superstring"""
return -(are.contained_in(superstring))

###############
# Aliases #
###############

@staticmethod
def less_than(y):
"""Less than y."""
return are.below(y)

@staticmethod
def greater_than(y):
"""Greater than y."""
return are.above(y)

@staticmethod
def greater_than_or_equal_to(y):
return are.above_or_equal_to(y)

@staticmethod
def less_than_or_equal_to(y):
return are.below_or_equal_to(y)
Copy link
Member

Choose a reason for hiding this comment

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

Based on: https://coveralls.io/builds/55559799/source?filename=datascience%2Fpredicates.py

We're missing test coverage on this method and a few others. The tests you've created are fantastic so far, if you could please add a few more for the missing test methods - this should be mergeable!


@staticmethod
def not_greater_than_or_equal_to(y):
"""Is neither above y nor equal to y"""
return are.not_above_or_equal_to(y)

@staticmethod
def not_less_than_or_equal_to(y):
"""Is neither below y nor equal to y"""
return are.not_below_or_equal_to(y)

@staticmethod
def not_greater_than(y):
"""Is not above y"""
return are.not_above(y)

@staticmethod
def not_less_than(y):
"""Is not below y"""
return are.not_below(y)

###############
# Combination #
###############
Expand Down
40 changes: 40 additions & 0 deletions tests/test_predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,46 @@ def test_between_or_equal_to():
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False]

#############
# Aliases #
#############

def test_greater_than_and_less_than():
"""Both f and g."""
p = are.greater_than(2) & are.less_than(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False]

def test_greater_than_or_less_than():
"""Either f or g."""
p = are.greater_than(3) | are.less_than(2)
ps = [p(x) for x in range(1, 6)]
assert ps == [True, False, False, True, True]

def test_greater_than():
"""Greater than y."""
p = are.greater_than(3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True]

def test_less_than():
"""Less than y."""
p = are.not_less_than(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True]

def test_greater_than_or_equal_to():
"""Greater than or equal to y."""
p = are.greater_than_or_equal_to(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True]

def test_less_than_or_equal_to():
"""Less than or equal to y."""
p = are.not_less_than_or_equal_to(3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True]


############
# Doctests #
Expand Down