Skip to content
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

Add type annotations for Indexing #1884

Merged
merged 2 commits into from
Nov 3, 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
4 changes: 2 additions & 2 deletions databricks/koalas/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9988,9 +9988,9 @@ class max_speed
if not is_list_like(indices) or isinstance(indices, (dict, set)):
raise ValueError("`indices` must be a list-like except dict or set")
if axis == 0:
return self.iloc[indices, :]
return self.iloc[indices, :] # type: ignore
else:
return self.iloc[:, indices]
return self.iloc[:, indices] # type: ignore

def eval(self, expr, inplace=False) -> Optional["DataFrame"]:
"""
Expand Down
10 changes: 5 additions & 5 deletions databricks/koalas/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#

"""
A base class to be monkey-patched to DataFrame/Column to behave similar to pandas DataFrame/Series.
A base class of DataFrame/Column to behave similar to pandas DataFrame/Series.
"""
from abc import ABCMeta, abstractmethod
from collections import Counter
Expand Down Expand Up @@ -2514,25 +2514,25 @@ def ffill(self, axis=None, inplace=False, limit=None):
pad = ffill

@property
def at(self):
def at(self) -> AtIndexer:
return AtIndexer(self)

at.__doc__ = AtIndexer.__doc__

@property
def iat(self):
def iat(self) -> iAtIndexer:
return iAtIndexer(self)

iat.__doc__ = iAtIndexer.__doc__

@property
def iloc(self):
def iloc(self) -> iLocIndexer:
return iLocIndexer(self)

iloc.__doc__ = iLocIndexer.__doc__

@property
def loc(self):
def loc(self) -> LocIndexer:
return LocIndexer(self)

loc.__doc__ = LocIndexer.__doc__
Expand Down
10 changes: 6 additions & 4 deletions databricks/koalas/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from collections import OrderedDict
from collections.abc import Iterable
from functools import reduce
from typing import Any, Optional, List, Tuple, TYPE_CHECKING
from typing import Any, Optional, List, Tuple, TYPE_CHECKING, Union

from pandas.api.types import is_list_like
from pyspark import sql as spark
Expand All @@ -30,12 +30,14 @@
from pyspark.sql.utils import AnalysisException
import numpy as np

from databricks import koalas as ks
from databricks.koalas.internal import (
InternalFrame,
NATURAL_ORDER_COLUMN_NAME,
SPARK_DEFAULT_SERIES_NAME,
)
from databricks.koalas.exceptions import SparkPandasIndexingError, SparkPandasNotImplementedError
from databricks.koalas.typedef import Scalar
from databricks.koalas.utils import (
is_name_like_tuple,
is_name_like_value,
Expand Down Expand Up @@ -123,7 +125,7 @@ class AtIndexer(IndexerLike):
array([ 4, 20])
"""

def __getitem__(self, key):
def __getitem__(self, key) -> Union["ks.Series", "ks.DataFrame", Scalar]:
if self._is_df:
if not isinstance(key, tuple) or len(key) != 2:
raise TypeError("Use DataFrame.at like .at[row_index, column_name]")
Expand Down Expand Up @@ -212,7 +214,7 @@ class iAtIndexer(IndexerLike):
2
"""

def __getitem__(self, key):
def __getitem__(self, key) -> Union["ks.Series", "ks.DataFrame", Scalar]:
if self._is_df:
if not isinstance(key, tuple) or len(key) != 2:
raise TypeError(
Expand Down Expand Up @@ -387,7 +389,7 @@ def _select_cols_else(
""" Select columns by other type key. """
pass

def __getitem__(self, key):
def __getitem__(self, key) -> Union["ks.Series", "ks.DataFrame"]:
from databricks.koalas.frame import DataFrame
from databricks.koalas.series import Series, first_series

Expand Down