Skip to content

TYP: misc #46513

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 5 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
# passed in, a DataFrame is always returned.
NDFrameT = TypeVar("NDFrameT", bound="NDFrame")

NumpyIndexT = TypeVar("NumpyIndexT", np.ndarray, "Index")

Axis = Union[str, int]
IndexLabel = Union[Hashable, Sequence[Hashable]]
Level = Union[Hashable, int]
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ def asi8(self) -> npt.NDArray[np.int64]:
# ----------------------------------------------------------------
# Rendering Methods

def _format_native_types(self, *, na_rep="NaT", date_format=None):
def _format_native_types(
self, *, na_rep="NaT", date_format=None
) -> npt.NDArray[np.object_]:
"""
Helper method for astype when converting to strings.

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ def _formatter(self, boxed: bool = False):
@dtl.ravel_compat
def _format_native_types(
self, *, na_rep="NaT", date_format=None, **kwargs
) -> np.ndarray:
) -> npt.NDArray[np.object_]:
"""
actually format my specific types
"""
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from pandas._typing import (
DtypeObj,
NpDtype,
npt,
)
from pandas.compat.numpy import function as nv
from pandas.util._validators import validate_endpoints
Expand Down Expand Up @@ -431,7 +432,7 @@ def _formatter(self, boxed: bool = False):
@dtl.ravel_compat
def _format_native_types(
self, *, na_rep="NaT", date_format=None, **kwargs
) -> np.ndarray:
) -> npt.NDArray[np.object_]:
from pandas.io.formats.format import get_format_timedelta64

formatter = get_format_timedelta64(self._ndarray, na_rep)
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,9 @@ def to_native_types(self, slicer=None, **kwargs) -> np.ndarray:
values = values[slicer]
return values._format_native_types(**kwargs)

def _format_native_types(self, *, na_rep="", quoting=None, **kwargs):
def _format_native_types(
self, *, na_rep="", quoting=None, **kwargs
) -> npt.NDArray[np.object_]:
"""
Actually format specific types of the index.
"""
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,9 @@ def _format_with_header(self, header: list[str], na_rep: str) -> list[str]:
# matches base class except for whitespace padding
return header + list(self._format_native_types(na_rep=na_rep))

def _format_native_types(self, *, na_rep="NaN", quoting=None, **kwargs):
def _format_native_types(
self, *, na_rep="NaN", quoting=None, **kwargs
) -> npt.NDArray[np.object_]:
# GH 28210: use base method but with different default na_rep
return super()._format_native_types(na_rep=na_rep, quoting=quoting, **kwargs)

Expand Down
4 changes: 3 additions & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,9 @@ def _formatter_func(self, tup):
formatter_funcs = [level._formatter_func for level in self.levels]
return tuple(func(val) for func, val in zip(formatter_funcs, tup))

def _format_native_types(self, *, na_rep="nan", **kwargs):
def _format_native_types(
self, *, na_rep="nan", **kwargs
) -> npt.NDArray[np.object_]:
new_levels = []
new_codes = []

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def _assert_safe_casting(cls, data: np.ndarray, subarr: np.ndarray) -> None:

def _format_native_types(
self, *, na_rep="", float_format=None, decimal=".", quoting=None, **kwargs
):
) -> npt.NDArray[np.object_]:
from pandas.io.formats.format import FloatArrayFormatter

if is_float_dtype(self.dtype):
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/reshape/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import numpy as np

from pandas._typing import NumpyIndexT

from pandas.core.dtypes.common import is_list_like


Expand Down Expand Up @@ -54,7 +56,7 @@ def cartesian_product(X):
return [tile_compat(np.repeat(x, b[i]), np.product(a[i])) for i, x in enumerate(X)]


def tile_compat(arr, num: int):
def tile_compat(arr: NumpyIndexT, num: int) -> NumpyIndexT:
"""
Index compat for np.tile.

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/csvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(

self.filepath_or_buffer = path_or_buf
self.encoding = encoding
self.compression = compression
self.compression: CompressionOptions = compression
self.mode = mode
self.storage_options = storage_options

Expand Down