Skip to content

TYP : DataFrame.(merge, join) core.reshape.merge.(merge, ...) (easy) #38468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
IndexLabel = Union[Label, Sequence[Label]]
Level = Union[Label, int]
Shape = Tuple[int, ...]
Suffixes = Tuple[str, str]
Ordered = Optional[bool]
JSONSerializable = Optional[Union[PythonScalar, List, Dict]]
Axes = Collection
Expand Down
38 changes: 23 additions & 15 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@
FormattersType,
FrameOrSeriesUnion,
IndexKeyFunc,
IndexLabel,
Label,
Level,
Renamer,
StorageOptions,
Suffixes,
ValueKeyFunc,
)
from pandas.compat._optional import import_optional_dependency
Expand Down Expand Up @@ -8028,8 +8030,8 @@ def append(

def join(
self,
other,
on=None,
other: FrameOrSeriesUnion,
on: Optional[IndexLabel] = None,
how: str = "left",
lsuffix: str = "",
rsuffix: str = "",
Expand Down Expand Up @@ -8157,7 +8159,13 @@ def join(
)

def _join_compat(
self, other, on=None, how="left", lsuffix="", rsuffix="", sort=False
self,
other: FrameOrSeriesUnion,
on: Optional[IndexLabel] = None,
how: str = "left",
lsuffix: str = "",
rsuffix: str = "",
sort: bool = False,
):
from pandas.core.reshape.concat import concat
from pandas.core.reshape.merge import merge
Expand Down Expand Up @@ -8222,18 +8230,18 @@ def _join_compat(
@Appender(_merge_doc, indents=2)
def merge(
self,
right,
how="inner",
on=None,
left_on=None,
right_on=None,
left_index=False,
right_index=False,
sort=False,
suffixes=("_x", "_y"),
copy=True,
indicator=False,
validate=None,
right: FrameOrSeriesUnion,
how: str = "inner",
on: Optional[IndexLabel] = None,
left_on: Optional[IndexLabel] = None,
right_on: Optional[IndexLabel] = None,
left_index: bool = False,
right_index: bool = False,
sort: bool = False,
suffixes: Suffixes = ("_x", "_y"),
copy: bool = True,
indicator: bool = False,
validate: Optional[str] = None,
) -> DataFrame:
from pandas.core.reshape.merge import merge

Expand Down
96 changes: 51 additions & 45 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
import numpy as np

from pandas._libs import Timedelta, hashtable as libhashtable, join as libjoin, lib
from pandas._typing import ArrayLike, FrameOrSeries, FrameOrSeriesUnion
from pandas._typing import (
ArrayLike,
FrameOrSeries,
FrameOrSeriesUnion,
IndexLabel,
Suffixes,
)
from pandas.errors import MergeError
from pandas.util._decorators import Appender, Substitution

Expand Down Expand Up @@ -57,19 +63,19 @@
@Substitution("\nleft : DataFrame")
@Appender(_merge_doc, indents=0)
def merge(
left,
right,
left: FrameOrSeriesUnion,
right: FrameOrSeriesUnion,
how: str = "inner",
on=None,
left_on=None,
right_on=None,
on: Optional[IndexLabel] = None,
left_on: Optional[IndexLabel] = None,
right_on: Optional[IndexLabel] = None,
left_index: bool = False,
right_index: bool = False,
sort: bool = False,
suffixes=("_x", "_y"),
suffixes: Suffixes = ("_x", "_y"),
copy: bool = True,
indicator: bool = False,
validate=None,
validate: Optional[str] = None,
) -> "DataFrame":
op = _MergeOperation(
left,
Expand Down Expand Up @@ -151,15 +157,15 @@ def _groupby_and_merge(by, on, left: "DataFrame", right: "DataFrame", merge_piec


def merge_ordered(
left,
right,
on=None,
left_on=None,
right_on=None,
left: "DataFrame",
right: "DataFrame",
on: Optional[IndexLabel] = None,
left_on: Optional[IndexLabel] = None,
right_on: Optional[IndexLabel] = None,
left_by=None,
right_by=None,
fill_method=None,
suffixes=("_x", "_y"),
fill_method: Optional[str] = None,
suffixes: Suffixes = ("_x", "_y"),
how: str = "outer",
) -> "DataFrame":
"""
Expand Down Expand Up @@ -294,17 +300,17 @@ def _merger(x, y):


def merge_asof(
left,
right,
on=None,
left_on=None,
right_on=None,
left: "DataFrame",
right: "DataFrame",
on: Optional[IndexLabel] = None,
left_on: Optional[IndexLabel] = None,
right_on: Optional[IndexLabel] = None,
left_index: bool = False,
right_index: bool = False,
by=None,
left_by=None,
right_by=None,
suffixes=("_x", "_y"),
suffixes: Suffixes = ("_x", "_y"),
tolerance=None,
allow_exact_matches: bool = True,
direction: str = "backward",
Expand Down Expand Up @@ -583,17 +589,17 @@ def __init__(
left: FrameOrSeriesUnion,
right: FrameOrSeriesUnion,
how: str = "inner",
on=None,
left_on=None,
right_on=None,
axis=1,
on: Optional[IndexLabel] = None,
left_on: Optional[IndexLabel] = None,
right_on: Optional[IndexLabel] = None,
axis: int = 1,
left_index: bool = False,
right_index: bool = False,
sort: bool = True,
suffixes=("_x", "_y"),
suffixes: Suffixes = ("_x", "_y"),
copy: bool = True,
indicator: bool = False,
validate=None,
validate: Optional[str] = None,
):
_left = _validate_operand(left)
_right = _validate_operand(right)
Expand Down Expand Up @@ -1224,7 +1230,7 @@ def _maybe_coerce_merge_keys(self):
self.right = self.right.assign(**{name: self.right[name].astype(typ)})

def _create_cross_configuration(
self, left, right
self, left: "DataFrame", right: "DataFrame"
) -> Tuple["DataFrame", "DataFrame", str, str]:
"""
Creates the configuration to dispatch the cross operation to inner join,
Expand Down Expand Up @@ -1540,17 +1546,17 @@ class _OrderedMerge(_MergeOperation):

def __init__(
self,
left,
right,
on=None,
left_on=None,
right_on=None,
left: "DataFrame",
right: "DataFrame",
on: Optional[IndexLabel] = None,
left_on: Optional[IndexLabel] = None,
right_on: Optional[IndexLabel] = None,
left_index: bool = False,
right_index: bool = False,
axis=1,
suffixes=("_x", "_y"),
axis: int = 1,
suffixes: Suffixes = ("_x", "_y"),
copy: bool = True,
fill_method=None,
fill_method: Optional[str] = None,
how: str = "outer",
):

Expand Down Expand Up @@ -1634,20 +1640,20 @@ class _AsOfMerge(_OrderedMerge):

def __init__(
self,
left,
right,
on=None,
left_on=None,
right_on=None,
left: "DataFrame",
right: "DataFrame",
on: Optional[IndexLabel] = None,
left_on: Optional[IndexLabel] = None,
right_on: Optional[IndexLabel] = None,
left_index: bool = False,
right_index: bool = False,
by=None,
left_by=None,
right_by=None,
axis=1,
suffixes=("_x", "_y"),
axis: int = 1,
suffixes: Suffixes = ("_x", "_y"),
copy: bool = True,
fill_method=None,
fill_method: Optional[str] = None,
how: str = "asof",
tolerance=None,
allow_exact_matches: bool = True,
Expand Down Expand Up @@ -2150,7 +2156,7 @@ def _validate_operand(obj: FrameOrSeries) -> "DataFrame":
)


def _items_overlap_with_suffix(left: Index, right: Index, suffixes: Tuple[str, str]):
def _items_overlap_with_suffix(left: Index, right: Index, suffixes: Suffixes):
"""
Suffixes type validation.

Expand Down