Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b19c203

Browse files
authoredMay 6, 2022
PERF: Remove unnecessary(?) asof join functions (#46943)
1 parent 0d8f588 commit b19c203

File tree

2 files changed

+19
-77
lines changed

2 files changed

+19
-77
lines changed
 

‎pandas/_libs/join.pyx

Lines changed: 9 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -839,11 +839,16 @@ def asof_join_nearest_on_X_by_Y(numeric_t[:] left_values,
839839
by_t[:] left_by_values,
840840
by_t[:] right_by_values,
841841
bint allow_exact_matches=True,
842-
tolerance=None):
842+
tolerance=None,
843+
bint use_hashtable=True):
843844

844845
cdef:
845846
ndarray[intp_t] bli, bri, fli, fri
846847

848+
ndarray[intp_t] left_indexer, right_indexer
849+
Py_ssize_t left_size, i
850+
numeric_t bdiff, fdiff
851+
847852
# search both forward and backward
848853
bli, bri = asof_join_backward_on_X_by_Y(
849854
left_values,
@@ -852,6 +857,7 @@ def asof_join_nearest_on_X_by_Y(numeric_t[:] left_values,
852857
right_by_values,
853858
allow_exact_matches,
854859
tolerance,
860+
use_hashtable
855861
)
856862
fli, fri = asof_join_forward_on_X_by_Y(
857863
left_values,
@@ -860,26 +866,11 @@ def asof_join_nearest_on_X_by_Y(numeric_t[:] left_values,
860866
right_by_values,
861867
allow_exact_matches,
862868
tolerance,
869+
use_hashtable
863870
)
864871

865-
return _choose_smaller_timestamp(left_values, right_values, bli, bri, fli, fri)
866-
867-
868-
cdef _choose_smaller_timestamp(
869-
numeric_t[:] left_values,
870-
numeric_t[:] right_values,
871-
ndarray[intp_t] bli,
872-
ndarray[intp_t] bri,
873-
ndarray[intp_t] fli,
874-
ndarray[intp_t] fri,
875-
):
876-
cdef:
877-
ndarray[intp_t] left_indexer, right_indexer
878-
Py_ssize_t left_size, i
879-
numeric_t bdiff, fdiff
880-
872+
# choose the smaller timestamp
881873
left_size = len(left_values)
882-
883874
left_indexer = np.empty(left_size, dtype=np.intp)
884875
right_indexer = np.empty(left_size, dtype=np.intp)
885876

@@ -894,55 +885,3 @@ cdef _choose_smaller_timestamp(
894885
left_indexer[i] = bli[i]
895886

896887
return left_indexer, right_indexer
897-
898-
899-
# ----------------------------------------------------------------------
900-
# asof_join
901-
# ----------------------------------------------------------------------
902-
903-
def asof_join_backward(numeric_t[:] left_values,
904-
numeric_t[:] right_values,
905-
bint allow_exact_matches=True,
906-
tolerance=None):
907-
908-
return asof_join_backward_on_X_by_Y(
909-
left_values,
910-
right_values,
911-
None,
912-
None,
913-
allow_exact_matches=allow_exact_matches,
914-
tolerance=tolerance,
915-
use_hashtable=False,
916-
)
917-
918-
919-
def asof_join_forward(numeric_t[:] left_values,
920-
numeric_t[:] right_values,
921-
bint allow_exact_matches=True,
922-
tolerance=None):
923-
return asof_join_forward_on_X_by_Y(
924-
left_values,
925-
right_values,
926-
None,
927-
None,
928-
allow_exact_matches=allow_exact_matches,
929-
tolerance=tolerance,
930-
use_hashtable=False,
931-
)
932-
933-
934-
def asof_join_nearest(numeric_t[:] left_values,
935-
numeric_t[:] right_values,
936-
bint allow_exact_matches=True,
937-
tolerance=None):
938-
939-
cdef:
940-
ndarray[intp_t] bli, bri, fli, fri
941-
942-
# search both forward and backward
943-
bli, bri = asof_join_backward(left_values, right_values,
944-
allow_exact_matches, tolerance)
945-
fli, fri = asof_join_forward(left_values, right_values,
946-
allow_exact_matches, tolerance)
947-
948-
return _choose_smaller_timestamp(left_values, right_values, bli, bri, fli, fri)

‎pandas/core/reshape/merge.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,11 +1691,6 @@ def get_result(self) -> DataFrame:
16911691
return result
16921692

16931693

1694-
def _asof_function(direction: str):
1695-
name = f"asof_join_{direction}"
1696-
return getattr(libjoin, name, None)
1697-
1698-
16991694
def _asof_by_function(direction: str):
17001695
name = f"asof_join_{direction}_on_X_by_Y"
17011696
return getattr(libjoin, name, None)
@@ -2017,8 +2012,16 @@ def injection(obj):
20172012
)
20182013
else:
20192014
# choose appropriate function by type
2020-
func = _asof_function(self.direction)
2021-
return func(left_values, right_values, self.allow_exact_matches, tolerance)
2015+
func = _asof_by_function(self.direction)
2016+
return func(
2017+
left_values,
2018+
right_values,
2019+
None,
2020+
None,
2021+
self.allow_exact_matches,
2022+
tolerance,
2023+
False,
2024+
)
20222025

20232026

20242027
def _get_multiindex_indexer(

0 commit comments

Comments
 (0)
Please sign in to comment.