Skip to content

[WIP] Annotate DataFrame (Part 3) #28575

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

Closed
wants to merge 8 commits into from
Closed
16 changes: 9 additions & 7 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ def to_string(
# ----------------------------------------------------------------------

@property
def style(self):
def style(self) -> "Styler":
"""
Returns a Styler object.

Expand Down Expand Up @@ -890,7 +890,7 @@ def items(self) -> Iterable[Tuple[Optional[Hashable], Series]]:
def iteritems(self):
yield from self.items()

def iterrows(self):
def iterrows(self) -> Iterable[Tuple[Index, Series]]:
"""
Iterate over DataFrame rows as (index, Series) pairs.

Expand Down Expand Up @@ -1022,13 +1022,15 @@ def itertuples(self, index=True, name="Pandas"):
# fallback to regular tuples
return zip(*arrays)

def __len__(self):
def __len__(self) -> int:
"""
Returns length of info axis, but here we use the index.
"""
return len(self.index)

def dot(self, other):
def dot(
self, other: Union[Series, DataFrame, np.ndarray]
) -> Union[Series, DataFrame, np.ndarray]:
"""
Compute the matrix multiplication between the DataFrame and other.

Expand Down Expand Up @@ -1139,13 +1141,13 @@ def dot(self, other):
else: # pragma: no cover
raise TypeError("unsupported type: {oth}".format(oth=type(other)))

def __matmul__(self, other):
def __matmul__(self, other: Union[Series, DataFrame]) -> Union[Series, DataFrame]:
"""
Matrix multiplication using binary `@` operator in Python>=3.5.
"""
return self.dot(other)

def __rmatmul__(self, other):
def __rmatmul__(self, other: Union[Series, DataFrame]) -> Union[Series, DataFrame]:
"""
Matrix multiplication using binary `@` operator in Python>=3.5.
"""
Expand Down Expand Up @@ -4825,7 +4827,7 @@ def drop_duplicates(self, subset=None, keep="first", inplace=False):
duplicated = self.duplicated(subset, keep=keep)

if inplace:
inds, = (-duplicated)._ndarray_values.nonzero()
(inds,) = (-duplicated)._ndarray_values.nonzero()
new_data = self._data.take(inds)
self._update_inplace(new_data)
else:
Expand Down