Skip to content

Commit 58a7da6

Browse files
committed
create type for Axes in _typing and make parameters of __init__ optional
1 parent 305329e commit 58a7da6

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
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, AnyStr, TypeVar, Union
2+
from typing import IO, AnyStr, Iterable, TypeVar, Union
33

44
import numpy as np
55

@@ -22,3 +22,6 @@
2222
Timedelta)
2323
Dtype = Union[str, np.dtype, ExtensionDtype]
2424
FilePathOrBuffer = Union[str, Path, IO[AnyStr]]
25+
26+
# Type for index and columns of DataFrame
27+
Axes = Iterable[Union[ABCIndexClass, Iterable[str]]]

pandas/core/frame.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from pandas._libs import lib, algos as libalgos
2727

28-
from pandas._typing import ArrayLike, Dtype
28+
from pandas._typing import ArrayLike, Axes, Dtype
2929

3030
from pandas.util._decorators import (Appender, Substitution,
3131
rewrite_axis_style_signature,
@@ -378,10 +378,10 @@ def _constructor_expanddim(self):
378378

379379
def __init__(self,
380380
data=None,
381-
index: ArrayLike = None,
382-
columns: ArrayLike = None,
383-
dtype: Dtype = None,
384-
copy: bool = False) -> None:
381+
index: Optional[Axes] = None,
382+
columns: Optional[Axes] = None,
383+
dtype: Optional[Dtype] = None,
384+
copy: Optional[bool] = False) -> None:
385385
if data is None:
386386
data = {}
387387
if dtype is not None:
@@ -477,7 +477,7 @@ def __init__(self,
477477
# ----------------------------------------------------------------------
478478

479479
@property
480-
def axes(self) -> List[ArrayLike]:
480+
def axes(self) -> List[Index]:
481481
"""
482482
Return a list representing the axes of the DataFrame.
483483

0 commit comments

Comments
 (0)