From 928b770213a3a303588ecbf0121fd0cb3b394860 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 7 Apr 2021 16:01:11 -0700 Subject: [PATCH] TYP: join.pyi --- pandas/_libs/join.pyi | 144 +++++++++++++++++++++++++++++++++++ pandas/core/reshape/merge.py | 18 ++++- 2 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 pandas/_libs/join.pyi diff --git a/pandas/_libs/join.pyi b/pandas/_libs/join.pyi new file mode 100644 index 0000000000000..4ae3ef0781dde --- /dev/null +++ b/pandas/_libs/join.pyi @@ -0,0 +1,144 @@ +import numpy as np + +def inner_join( + left: np.ndarray, # const intp_t[:] + right: np.ndarray, # const intp_t[:] + max_groups: int, +) -> tuple[ + np.ndarray, # np.ndarray[np.intp] + np.ndarray, # np.ndarray[np.intp] +]: ... + + +def left_outer_join( + left: np.ndarray, # const intp_t[:] + right: np.ndarray, # const intp_t[:] + max_groups: int, + sort: bool = True, +) -> tuple[ + np.ndarray, # np.ndarray[np.intp] + np.ndarray, # np.ndarray[np.intp] +]: ... + + +def full_outer_join( + left: np.ndarray, # const intp_t[:] + right: np.ndarray, # const intp_t[:] + max_groups: int, +) -> tuple[ + np.ndarray, # np.ndarray[np.intp] + np.ndarray, # np.ndarray[np.intp] +]: ... + + +def ffill_indexer( + indexer: np.ndarray # const intp_t[:] +) -> np.ndarray: ... # np.ndarray[np.intp] + + +def left_join_indexer_unique( + left: np.ndarray, # ndarray[join_t] + right: np.ndarray, # ndarray[join_t] +) -> np.ndarray: ... # np.ndarray[np.intp] + + +def left_join_indexer( + left: np.ndarray, # ndarray[join_t] + right: np.ndarray, # ndarray[join_t] +) -> tuple[ + np.ndarray, # np.ndarray[join_t] + np.ndarray, # np.ndarray[np.intp] + np.ndarray, # np.ndarray[np.intp] +]: ... + + +def inner_join_indexer( + left: np.ndarray, # ndarray[join_t] + right: np.ndarray, # ndarray[join_t] +) -> tuple[ + np.ndarray, # np.ndarray[join_t] + np.ndarray, # np.ndarray[np.intp] + np.ndarray, # np.ndarray[np.intp] +]: ... + + +def outer_join_indexer( + left: np.ndarray, # ndarray[join_t] + right: np.ndarray, # ndarray[join_t] +) -> tuple[ + np.ndarray, # np.ndarray[join_t] + np.ndarray, # np.ndarray[np.intp] + np.ndarray, # np.ndarray[np.intp] +]: ... + + +def asof_join_backward_on_X_by_Y( + left_values: np.ndarray, # asof_t[:] + right_values: np.ndarray, # asof_t[:] + left_by_values: np.ndarray, # by_t[:] + right_by_values: np.ndarray, # by_t[:] + allow_exact_matches: bool = True, + tolerance=None, +) -> tuple[ + np.ndarray, # np.ndarray[np.intp] + np.ndarray, # np.ndarray[np.intp] +]: ... + + +def asof_join_forward_on_X_by_Y( + left_values: np.ndarray, # asof_t[:] + right_values: np.ndarray, # asof_t[:] + left_by_values: np.ndarray, # by_t[:] + right_by_values: np.ndarray, # by_t[:] + allow_exact_matches: bool = True, + tolerance=None, +) -> tuple[ + np.ndarray, # np.ndarray[np.intp] + np.ndarray, # np.ndarray[np.intp] +]: ... + + +def asof_join_nearest_on_X_by_Y( + left_values: np.ndarray, # asof_t[:] + right_values: np.ndarray, # asof_t[:] + left_by_values: np.ndarray, # by_t[:] + right_by_values: np.ndarray, # by_t[:] + allow_exact_matches: bool = True, + tolerance=None, +) -> tuple[ + np.ndarray, # np.ndarray[np.intp] + np.ndarray, # np.ndarray[np.intp] +]: ... + + +def asof_join_backward( + left_values: np.ndarray, # asof_t[:] + right_values: np.ndarray, # asof_t[:] + allow_exact_matches: bool = True, + tolerance=None, +) -> tuple[ + np.ndarray, # np.ndarray[np.intp] + np.ndarray, # np.ndarray[np.intp] +]: ... + + +def asof_join_forward( + left_values: np.ndarray, # asof_t[:] + right_values: np.ndarray, # asof_t[:] + allow_exact_matches: bool = True, + tolerance=None, +) -> tuple[ + np.ndarray, # np.ndarray[np.intp] + np.ndarray, # np.ndarray[np.intp] +]: ... + + +def asof_join_nearest( + left_values: np.ndarray, # asof_t[:] + right_values: np.ndarray, # asof_t[:] + allow_exact_matches: bool = True, + tolerance=None, +) -> tuple[ + np.ndarray, # np.ndarray[np.intp] + np.ndarray, # np.ndarray[np.intp] +]: ... diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 13e528f38f3bf..45822a774011f 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -1485,7 +1485,8 @@ def get_join_indexers( "outer": libjoin.full_outer_join, }[how] - return join_func(lkey, rkey, count, **kwargs) + # error: Cannot call function of unknown type + return join_func(lkey, rkey, count, **kwargs) # type: ignore[operator] def restore_dropped_levels_multijoin( @@ -1624,9 +1625,20 @@ def get_result(self) -> DataFrame: self.left._info_axis, self.right._info_axis, self.suffixes ) + left_join_indexer: np.ndarray | None + right_join_indexer: np.ndarray | None + if self.fill_method == "ffill": - left_join_indexer = libjoin.ffill_indexer(left_indexer) - right_join_indexer = libjoin.ffill_indexer(right_indexer) + # error: Argument 1 to "ffill_indexer" has incompatible type + # "Optional[ndarray]"; expected "ndarray" + left_join_indexer = libjoin.ffill_indexer( + left_indexer # type: ignore[arg-type] + ) + # error: Argument 1 to "ffill_indexer" has incompatible type + # "Optional[ndarray]"; expected "ndarray" + right_join_indexer = libjoin.ffill_indexer( + right_indexer # type: ignore[arg-type] + ) else: left_join_indexer = left_indexer right_join_indexer = right_indexer