Skip to content

Commit

Permalink
Merge pull request #84 from realratchet/master
Browse files Browse the repository at this point in the history
Filter is now typesafe
  • Loading branch information
realratchet authored Sep 25, 2023
2 parents 1446b17 + 210f279 commit cf2aabf
Showing 2 changed files with 25 additions and 15 deletions.
38 changes: 24 additions & 14 deletions tablite/redux.py
Original file line number Diff line number Diff line change
@@ -114,22 +114,32 @@ def _filter_using_list_of_dicts(T, expressions, filter_type, tqdm=_tqdm):
f"Assymmetric dataset: {c1} has {len(dset_A)} values, whilst {c2} has {len(dset_B)} values."
)
# Evaluate
if expr == ">":
result = dset_A > dset_B
elif expr == ">=":
result = dset_A >= dset_B
elif expr == "==":
result = dset_A == dset_B
elif expr == "<":
result = dset_A < dset_B
elif expr == "<=":
result = dset_A <= dset_B
elif expr == "!=":
result = dset_A != dset_B
else: # it's a python evaluations (slow)
try:
if expr == ">":
result = dset_A > dset_B
elif expr == ">=":
result = dset_A >= dset_B
elif expr == "==":
result = dset_A == dset_B
elif expr == "<":
result = dset_A < dset_B
elif expr == "<=":
result = dset_A <= dset_B
elif expr == "!=":
result = dset_A != dset_B
else: # it's a python evaluations (slow)
f = filter_ops.get(expr)
assert callable(f)
result = list_to_np_array([f(a, b) for a, b in zip(dset_A, dset_B)])
except TypeError:
def safe_test(f, a, b):
try:
return f(a, b)
except TypeError:
return False
f = filter_ops.get(expr)
assert callable(f)
result = list_to_np_array([f(a, b) for a, b in zip(dset_A, dset_B)])
result = list_to_np_array([safe_test(f, a, b) for a, b in zip(dset_A, dset_B)])
bitmap[bit_index, start:end] = result

f = np.all if filter_type == "all" else np.any
2 changes: 1 addition & 1 deletion tablite/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
major, minor, patch = 2023, 7, "dev4"
major, minor, patch = 2023, 7, "dev5"
__version_info__ = (major, minor, patch)
__version__ = ".".join(str(i) for i in __version_info__)

0 comments on commit cf2aabf

Please sign in to comment.