Skip to content

Commit

Permalink
Annotate DataFrame (Part 1) (#26867)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavhrt authored and simonjayhawkins committed Sep 12, 2019
1 parent 6908be7 commit 3f40528
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 4 additions & 1 deletion pandas/_typing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import IO, TYPE_CHECKING, AnyStr, Optional, TypeVar, Union
from typing import IO, TYPE_CHECKING, AnyStr, Iterable, Optional, TypeVar, Union

import numpy as np

Expand Down Expand Up @@ -29,5 +29,8 @@
Axis = Union[str, int]
Ordered = Optional[bool]

# use Collection after we drop support for py35
Axes = Iterable

# to maintain type information across generic functions and parametrization
_T = TypeVar("_T")
18 changes: 13 additions & 5 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
)
from pandas.core.dtypes.missing import isna, notna

from pandas._typing import Axes, Dtype
from pandas.core import algorithms, common as com, nanops, ops
from pandas.core.accessor import CachedAccessor
from pandas.core.arrays import Categorical, ExtensionArray
Expand Down Expand Up @@ -370,7 +371,7 @@ class DataFrame(NDFrame):
"""

@property
def _constructor(self):
def _constructor(self) -> Type["DataFrame"]:
return DataFrame

_constructor_sliced = Series # type: Type[Series]
Expand All @@ -386,7 +387,14 @@ def _constructor_expanddim(self):
# ----------------------------------------------------------------------
# Constructors

def __init__(self, data=None, index=None, columns=None, dtype=None, copy=False):
def __init__(
self,
data=None,
index: Optional[Axes] = None,
columns: Optional[Axes] = None,
dtype: Optional[Dtype] = None,
copy: bool = False,
):
if data is None:
data = {}
if dtype is not None:
Expand Down Expand Up @@ -481,7 +489,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None, copy=False):
# ----------------------------------------------------------------------

@property
def axes(self):
def axes(self) -> List[Index]:
"""
Return a list representing the axes of the DataFrame.
Expand All @@ -498,7 +506,7 @@ def axes(self):
return [self.index, self.columns]

@property
def shape(self):
def shape(self) -> Tuple[int, int]:
"""
Return a tuple representing the dimensionality of the DataFrame.
Expand All @@ -520,7 +528,7 @@ def shape(self):
return len(self.index), len(self.columns)

@property
def _is_homogeneous_type(self):
def _is_homogeneous_type(self) -> bool:
"""
Whether all the columns in a DataFrame have the same type.
Expand Down

0 comments on commit 3f40528

Please sign in to comment.