Skip to content

TYP: Simple type fixes for ExtensionArray #41255

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 12 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update transpose and fillna to use consistent typing
  • Loading branch information
Dr-Irv committed May 2, 2021
commit 30b6dcb9d42cebf31f807541b27fcf5ebd86284c
1 change: 1 addition & 0 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
FrameOrSeries = TypeVar("FrameOrSeries", bound="NDFrame")

Axis = Union[str, int]
NumpyAxis = Union[Tuple[int], List[int], None]
IndexLabel = Union[Hashable, Sequence[Hashable]]
Level = Union[Hashable, int]
Shape = Tuple[int, ...]
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pandas._typing import (
ArrayLike,
Dtype,
NumpyAxis,
PositionalIndexer,
Shape,
)
Expand Down Expand Up @@ -1214,7 +1215,7 @@ def _formatter(self, boxed: bool = False) -> Callable[[Any], str | None]:
# Reshaping
# ------------------------------------------------------------------------

def transpose(self, *axes: tuple[int] | list[int] | None) -> ExtensionArray:
def transpose(self, axes: NumpyAxis = None) -> ExtensionArray:
"""
Return a transposed view on this array.

Expand Down
5 changes: 3 additions & 2 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Dtype,
DtypeObj,
IndexLabel,
NumpyAxis,
Shape,
final,
)
Expand Down Expand Up @@ -298,15 +299,15 @@ def _values(self) -> ExtensionArray | np.ndarray:
# must be defined here as a property for mypy
raise AbstractMethodError(self)

def transpose(self: _T, *args, **kwargs) -> _T:
def transpose(self: _T, axes: NumpyAxis = None) -> _T:
"""
Return the transpose, which is by definition self.

Returns
-------
%(klass)s
"""
nv.validate_transpose(args, kwargs)
nv.validate_transpose(axes, {})
return self

T = property(
Expand Down
23 changes: 12 additions & 11 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
IndexLabel,
Level,
NpDtype,
NumpyAxis,
PythonFuncType,
Renamer,
Scalar,
Expand Down Expand Up @@ -3189,7 +3190,7 @@ def memory_usage(self, index: bool = True, deep: bool = False) -> Series:
).append(result)
return result

def transpose(self, *args, copy: bool = False) -> DataFrame:
def transpose(self, axes: NumpyAxis = None, copy: bool = False) -> DataFrame:
"""
Transpose index and columns.

Expand All @@ -3199,7 +3200,7 @@ def transpose(self, *args, copy: bool = False) -> DataFrame:

Parameters
----------
*args : tuple, optional
axes : tuple or list, optional
Accepted for compatibility with NumPy.
copy : bool, default False
Whether to copy the data after transposing, even for DataFrames
Expand Down Expand Up @@ -3286,7 +3287,7 @@ def transpose(self, *args, copy: bool = False) -> DataFrame:
1 object
dtype: object
"""
nv.validate_transpose(args, {})
nv.validate_transpose(axes, {})
# construct the args

dtypes = list(self.dtypes)
Expand Down Expand Up @@ -5015,7 +5016,7 @@ def rename(
def fillna(
self,
value=...,
method: str | None = ...,
method: Literal["backfill", "bfill", "ffill", "pad"] | None = ...,
axis: Axis | None = ...,
inplace: Literal[False] = ...,
limit=...,
Expand All @@ -5027,7 +5028,7 @@ def fillna(
def fillna(
self,
value,
method: str | None,
method: Literal["backfill", "bfill", "ffill", "pad"] | None,
axis: Axis | None,
inplace: Literal[True],
limit=...,
Expand Down Expand Up @@ -5060,7 +5061,7 @@ def fillna(
def fillna(
self,
*,
method: str | None,
method: Literal["backfill", "bfill", "ffill", "pad"] | None,
inplace: Literal[True],
limit=...,
downcast=...,
Expand All @@ -5082,7 +5083,7 @@ def fillna(
def fillna(
self,
*,
method: str | None,
method: Literal["backfill", "bfill", "ffill", "pad"] | None,
axis: Axis | None,
inplace: Literal[True],
limit=...,
Expand All @@ -5106,7 +5107,7 @@ def fillna(
def fillna(
self,
value,
method: str | None,
method: Literal["backfill", "bfill", "ffill", "pad"] | None,
*,
inplace: Literal[True],
limit=...,
Expand All @@ -5118,7 +5119,7 @@ def fillna(
def fillna(
self,
value=...,
method: str | None = ...,
method: Literal["backfill", "bfill", "ffill", "pad"] | None = ...,
axis: Axis | None = ...,
inplace: bool = ...,
limit=...,
Expand All @@ -5129,8 +5130,8 @@ def fillna(
@doc(NDFrame.fillna, **_shared_doc_kwargs)
def fillna(
self,
value=None,
method: str | None = None,
value: Any | ArrayLike | None = None,
method: Literal["backfill", "bfill", "ffill", "pad"] | None = None,
axis: Axis | None = None,
inplace: bool = False,
limit=None,
Expand Down
16 changes: 8 additions & 8 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4594,7 +4594,7 @@ def drop(
def fillna(
self,
value=...,
method: str | None = ...,
method: Literal["backfill", "bfill", "ffill", "pad"] | None = ...,
axis: Axis | None = ...,
inplace: Literal[False] = ...,
limit=...,
Expand All @@ -4606,7 +4606,7 @@ def fillna(
def fillna(
self,
value,
method: str | None,
method: Literal["backfill", "bfill", "ffill", "pad"] | None,
axis: Axis | None,
inplace: Literal[True],
limit=...,
Expand Down Expand Up @@ -4639,7 +4639,7 @@ def fillna(
def fillna(
self,
*,
method: str | None,
method: Literal["backfill", "bfill", "ffill", "pad"] | None,
inplace: Literal[True],
limit=...,
downcast=...,
Expand All @@ -4661,7 +4661,7 @@ def fillna(
def fillna(
self,
*,
method: str | None,
method: Literal["backfill", "bfill", "ffill", "pad"] | None,
axis: Axis | None,
inplace: Literal[True],
limit=...,
Expand All @@ -4685,7 +4685,7 @@ def fillna(
def fillna(
self,
value,
method: str | None,
method: Literal["backfill", "bfill", "ffill", "pad"] | None,
*,
inplace: Literal[True],
limit=...,
Expand All @@ -4697,7 +4697,7 @@ def fillna(
def fillna(
self,
value=...,
method: str | None = ...,
method: Literal["backfill", "bfill", "ffill", "pad"] | None = ...,
axis: Axis | None = ...,
inplace: bool = ...,
limit=...,
Expand All @@ -4709,8 +4709,8 @@ def fillna(
@doc(NDFrame.fillna, **_shared_doc_kwargs) # type: ignore[has-type]
def fillna(
self,
value=None,
method=None,
value: Any | ArrayLike | None = None,
method: Literal["backfill", "bfill", "ffill", "pad"] | None = None,
axis=None,
inplace=False,
limit=None,
Expand Down