diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d51f9791..b519a72f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 + ### 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. diff --git a/datascience/predicates.py b/datascience/predicates.py index e412f2ede..006ef78d6 100644 --- a/datascience/predicates.py +++ b/datascience/predicates.py @@ -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) + + @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 # ############### diff --git a/tests/test_predicates.py b/tests/test_predicates.py index ca9d42f0e..b112280aa 100644 --- a/tests/test_predicates.py +++ b/tests/test_predicates.py @@ -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 #