Skip to content

Annotate DataFrame (Part 1) #26867

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 28 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bc01d66
type a few functions
vaibhavhrt Jun 15, 2019
5e70e01
fix flake errors
vaibhavhrt Jun 15, 2019
305329e
minor changes
vaibhavhrt Jun 15, 2019
58a7da6
create type for Axes in _typing and make parameters of __init__ optional
vaibhavhrt Jun 17, 2019
691d1bb
update from master
vaibhavhrt Jul 17, 2019
c54642f
WIP type for data
vaibhavhrt Jul 17, 2019
0fd42eb
move types for 'data' in 'frame.py' from 'pandas._typing'
vaibhavhrt Jul 24, 2019
38bf4e0
merge master
vaibhavhrt Jul 24, 2019
e413504
use ABCDataFrame instead of 'DataFrame'
vaibhavhrt Jul 25, 2019
77f93fc
merge master
vaibhavhrt Jul 25, 2019
5ec1c87
use Index instead of ABCIndex
vaibhavhrt Jul 26, 2019
161dfcc
merge master
vaibhavhrt Jul 26, 2019
17214ea
use typing.Dict instead of dict
vaibhavhrt Jul 26, 2019
fba0fcc
add more tyoes in data, error expected
vaibhavhrt Jul 29, 2019
4560a97
Merge branch 'master' into annotate-DataFrame
vaibhavhrt Aug 24, 2019
6da817c
remove anootation of data as it's causing problems
vaibhavhrt Aug 26, 2019
c4ceab0
remove unused import
vaibhavhrt Aug 26, 2019
8830f54
don't change anything in _typing
vaibhavhrt Aug 26, 2019
2e65291
put Axes back in pandas._typing
vaibhavhrt Aug 27, 2019
d99cc1a
format with black
vaibhavhrt Aug 28, 2019
c935b58
Merge branch 'master' into annotate-DataFrame
vaibhavhrt Aug 28, 2019
1740ef2
use Collection for Axes
vaibhavhrt Sep 7, 2019
a118f67
merge origin
vaibhavhrt Sep 7, 2019
f2edb32
revert Axes with comment
vaibhavhrt Sep 10, 2019
112f550
Apply suggestions from code review
vaibhavhrt Sep 11, 2019
8814eb3
Merge branch 'master' into annotate-DataFrame
vaibhavhrt Sep 12, 2019
4d78c4b
Merge branch 'annotate-DataFrame' of https://github.com/vaibhavhrt/pa…
vaibhavhrt Sep 12, 2019
d03e33c
Update _typing.py
WillAyd Sep 12, 2019
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
3 changes: 2 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 @@ -28,6 +28,7 @@
Scalar = Union[str, int, float]
Axis = Union[str, int]
Ordered = Optional[bool]
Axes = Iterable[Union["Index", Iterable[str]]]

# 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: Optional[bool] = False,
) -> None:
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