From 1b459205a1301ad7043575d35790ec274dfdcaa3 Mon Sep 17 00:00:00 2001 From: Eric Apostal Date: Thu, 8 Sep 2022 15:41:38 -0400 Subject: [PATCH 1/4] Adds Pythonic predicate aliases --- datascience/predicates.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/datascience/predicates.py b/datascience/predicates.py index e412f2ed..c6d5afde 100644 --- a/datascience/predicates.py +++ b/datascience/predicates.py @@ -126,6 +126,10 @@ def above_or_equal_to(y): check_iterable(y) return _combinable(lambda x: x >= y or _equal_or_float_equal(x, y)) + @staticmethod + def greater_than_or_equal_to(y): + return are.above_or_equal_to(y) + @staticmethod def below_or_equal_to(y): """Less than or equal to y.""" @@ -211,6 +215,41 @@ 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 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 # ############### From 2bed9ebc7f3233a8145d491ccc316b530ffff039 Mon Sep 17 00:00:00 2001 From: Eric Apostal Date: Thu, 8 Sep 2022 16:14:23 -0400 Subject: [PATCH 2/4] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c288d837..275368f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +### v0.17.6 +* Add pythonic aliases for comparison predicates. + ### v0.17.5 * Eliminated deprecation warnings involved arrays containing arrays/sequences. * Changed the column type of a table after a remove operation back to a NumPy array, as written in the documentation. From be1427acaeb7298061b070fae6fe9dd9cc2834ce Mon Sep 17 00:00:00 2001 From: Eric Apostal Date: Thu, 8 Sep 2022 18:33:51 -0400 Subject: [PATCH 3/4] add "less_than_or_equal_to" alias --- datascience/predicates.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/datascience/predicates.py b/datascience/predicates.py index c6d5afde..006ef78d 100644 --- a/datascience/predicates.py +++ b/datascience/predicates.py @@ -126,10 +126,6 @@ def above_or_equal_to(y): check_iterable(y) return _combinable(lambda x: x >= y or _equal_or_float_equal(x, y)) - @staticmethod - def greater_than_or_equal_to(y): - return are.above_or_equal_to(y) - @staticmethod def below_or_equal_to(y): """Less than or equal to y.""" @@ -230,6 +226,14 @@ 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""" From 064f162bb9e587cf0ef7ccd37733c4532fe06b70 Mon Sep 17 00:00:00 2001 From: Eric A Date: Sat, 31 Dec 2022 11:48:22 -0500 Subject: [PATCH 4/4] Added tests for predicates --- tests/test_predicates.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/test_predicates.py b/tests/test_predicates.py index e051efae..61fef5d0 100644 --- a/tests/test_predicates.py +++ b/tests/test_predicates.py @@ -63,6 +63,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 #