Skip to content

Commit c48ef62

Browse files
vaibhavhrtproost
authored andcommitted
Annotate DataFrame (Part 1) (pandas-dev#26867)
1 parent 4c11c54 commit c48ef62

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

pandas/_typing.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pathlib import Path
2-
from typing import IO, TYPE_CHECKING, AnyStr, Optional, TypeVar, Union
2+
from typing import IO, TYPE_CHECKING, AnyStr, Iterable, Optional, TypeVar, Union
33

44
import numpy as np
55

@@ -29,5 +29,8 @@
2929
Axis = Union[str, int]
3030
Ordered = Optional[bool]
3131

32+
# use Collection after we drop support for py35
33+
Axes = Iterable
34+
3235
# to maintain type information across generic functions and parametrization
3336
_T = TypeVar("_T")

pandas/core/frame.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
)
8181
from pandas.core.dtypes.missing import isna, notna
8282

83+
from pandas._typing import Axes, Dtype
8384
from pandas.core import algorithms, common as com, nanops, ops
8485
from pandas.core.accessor import CachedAccessor
8586
from pandas.core.arrays import Categorical, ExtensionArray
@@ -370,7 +371,7 @@ class DataFrame(NDFrame):
370371
"""
371372

372373
@property
373-
def _constructor(self):
374+
def _constructor(self) -> Type["DataFrame"]:
374375
return DataFrame
375376

376377
_constructor_sliced = Series # type: Type[Series]
@@ -386,7 +387,14 @@ def _constructor_expanddim(self):
386387
# ----------------------------------------------------------------------
387388
# Constructors
388389

389-
def __init__(self, data=None, index=None, columns=None, dtype=None, copy=False):
390+
def __init__(
391+
self,
392+
data=None,
393+
index: Optional[Axes] = None,
394+
columns: Optional[Axes] = None,
395+
dtype: Optional[Dtype] = None,
396+
copy: bool = False,
397+
):
390398
if data is None:
391399
data = {}
392400
if dtype is not None:
@@ -481,7 +489,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None, copy=False):
481489
# ----------------------------------------------------------------------
482490

483491
@property
484-
def axes(self):
492+
def axes(self) -> List[Index]:
485493
"""
486494
Return a list representing the axes of the DataFrame.
487495
@@ -498,7 +506,7 @@ def axes(self):
498506
return [self.index, self.columns]
499507

500508
@property
501-
def shape(self):
509+
def shape(self) -> Tuple[int, int]:
502510
"""
503511
Return a tuple representing the dimensionality of the DataFrame.
504512
@@ -520,7 +528,7 @@ def shape(self):
520528
return len(self.index), len(self.columns)
521529

522530
@property
523-
def _is_homogeneous_type(self):
531+
def _is_homogeneous_type(self) -> bool:
524532
"""
525533
Whether all the columns in a DataFrame have the same type.
526534

0 commit comments

Comments
 (0)