Skip to content

Commit

Permalink
manage None vs (None, None) return output
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel.oranyeli committed Sep 16, 2024
1 parent ef4f9f3 commit 9f9babc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
14 changes: 7 additions & 7 deletions janitor/functions/_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _numba_equi_join(
# this also lets us know if there are equi matches
keep_rows = slice_starts < slice_ends
if not keep_rows.any():
return None, None
return None
if not keep_rows.all():
left_index = left_index[keep_rows]
slice_starts = slice_starts[keep_rows]
Expand Down Expand Up @@ -247,7 +247,7 @@ def _numba_equi_join(
)

if left_index is None:
return None, None
return None

return left_index, right_index

Expand Down Expand Up @@ -571,14 +571,14 @@ def _numba_single_non_equi_join(
left=left, right=right, op=op, multiple_conditions=False, keep=keep
)
if outcome is None:
return None, None
return None
return outcome

outcome = _generic_func_cond_join(
left=left, right=right, op=op, multiple_conditions=True, keep="all"
)
if outcome is None:
return None, None
return None
left_index, right_index, starts = outcome
if op in less_than_join_types:
counts = right_index.size - starts
Expand Down Expand Up @@ -769,7 +769,7 @@ def _numba_multiple_non_equi_join(
op=op,
)
if result is None:
return None, None
return None
(
left_index,
right_index,
Expand Down Expand Up @@ -800,7 +800,7 @@ def _numba_multiple_non_equi_join(
booleans = starts == right_regions.shape[0]
# left_region should be <= right_region
if booleans.all(axis=None):
return None, None
return None
if booleans.any(axis=None):
booleans = ~booleans
starts = starts[booleans]
Expand All @@ -821,7 +821,7 @@ def _numba_multiple_non_equi_join(

booleans = booleans.any(axis=1)
if booleans.all(axis=None):
return None, None
return None
if booleans.any(axis=None):
booleans = ~booleans
left_regions = left_regions[booleans]
Expand Down
12 changes: 4 additions & 8 deletions janitor/functions/conditional_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,7 @@ def _conditional_join_compute(
op=op,
keep=keep,
)
if result[0] is None:
result = None

else:
result = _generic_func_cond_join(
left=df[left_on],
Expand Down Expand Up @@ -767,7 +766,7 @@ def _multiple_conditional_join_eq(
indices = _numba_equi_join(
df=left_df, right=right_df, eqs=eqs, ge_gt=ge_gt, le_lt=le_lt
)
if indices[0] is None:
if indices is None:
return None
if not rest:
return indices
Expand Down Expand Up @@ -875,10 +874,7 @@ def _multiple_conditional_join_le_lt(
condition for condition in conditions if condition not in gt_lt
]
if (len(gt_lt) > 1) and not conditions:
result = _numba_multiple_non_equi_join(df, right, gt_lt, keep=keep)
if result[0] is None:
return None
return result
return _numba_multiple_non_equi_join(df, right, gt_lt, keep=keep)
if len(gt_lt) == 1:
left_on, right_on, op = gt_lt[0]
indices = _numba_single_non_equi_join(
Expand All @@ -888,7 +884,7 @@ def _multiple_conditional_join_le_lt(
indices = _numba_multiple_non_equi_join(
df, right, gt_lt, keep="all"
)
if indices[0] is None:
if indices is None:
return None
else:
# there is an opportunity for optimization for range joins
Expand Down

0 comments on commit 9f9babc

Please sign in to comment.