Skip to content

Commit 9aeddee

Browse files
authored
TYP: misc (#46513)
1 parent 1b3bb88 commit 9aeddee

File tree

10 files changed

+22
-9
lines changed

10 files changed

+22
-9
lines changed

pandas/_typing.py

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
# passed in, a DataFrame is always returned.
105105
NDFrameT = TypeVar("NDFrameT", bound="NDFrame")
106106

107+
NumpyIndexT = TypeVar("NumpyIndexT", np.ndarray, "Index")
108+
107109
Axis = Union[str, int]
108110
IndexLabel = Union[Hashable, Sequence[Hashable]]
109111
Level = Union[Hashable, int]

pandas/core/arrays/datetimelike.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ def asi8(self) -> npt.NDArray[np.int64]:
295295
# ----------------------------------------------------------------
296296
# Rendering Methods
297297

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

pandas/core/arrays/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ def _formatter(self, boxed: bool = False):
635635
@dtl.ravel_compat
636636
def _format_native_types(
637637
self, *, na_rep="NaT", date_format=None, **kwargs
638-
) -> np.ndarray:
638+
) -> npt.NDArray[np.object_]:
639639
"""
640640
actually format my specific types
641641
"""

pandas/core/arrays/timedeltas.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from pandas._typing import (
3838
DtypeObj,
3939
NpDtype,
40+
npt,
4041
)
4142
from pandas.compat.numpy import function as nv
4243
from pandas.util._validators import validate_endpoints
@@ -431,7 +432,7 @@ def _formatter(self, boxed: bool = False):
431432
@dtl.ravel_compat
432433
def _format_native_types(
433434
self, *, na_rep="NaT", date_format=None, **kwargs
434-
) -> np.ndarray:
435+
) -> npt.NDArray[np.object_]:
435436
from pandas.io.formats.format import get_format_timedelta64
436437

437438
formatter = get_format_timedelta64(self._ndarray, na_rep)

pandas/core/indexes/base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,9 @@ def to_native_types(self, slicer=None, **kwargs) -> np.ndarray:
15111511
values = values[slicer]
15121512
return values._format_native_types(**kwargs)
15131513

1514-
def _format_native_types(self, *, na_rep="", quoting=None, **kwargs):
1514+
def _format_native_types(
1515+
self, *, na_rep="", quoting=None, **kwargs
1516+
) -> npt.NDArray[np.object_]:
15151517
"""
15161518
Actually format specific types of the index.
15171519
"""

pandas/core/indexes/interval.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,9 @@ def _format_with_header(self, header: list[str], na_rep: str) -> list[str]:
820820
# matches base class except for whitespace padding
821821
return header + list(self._format_native_types(na_rep=na_rep))
822822

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

pandas/core/indexes/multi.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,9 @@ def _formatter_func(self, tup):
13061306
formatter_funcs = [level._formatter_func for level in self.levels]
13071307
return tuple(func(val) for func, val in zip(formatter_funcs, tup))
13081308

1309-
def _format_native_types(self, *, na_rep="nan", **kwargs):
1309+
def _format_native_types(
1310+
self, *, na_rep="nan", **kwargs
1311+
) -> npt.NDArray[np.object_]:
13101312
new_levels = []
13111313
new_codes = []
13121314

pandas/core/indexes/numeric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def _assert_safe_casting(cls, data: np.ndarray, subarr: np.ndarray) -> None:
276276

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

282282
if is_float_dtype(self.dtype):

pandas/core/reshape/util.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import numpy as np
22

3+
from pandas._typing import NumpyIndexT
4+
35
from pandas.core.dtypes.common import is_list_like
46

57

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

5658

57-
def tile_compat(arr, num: int):
59+
def tile_compat(arr: NumpyIndexT, num: int) -> NumpyIndexT:
5860
"""
5961
Index compat for np.tile.
6062

pandas/io/formats/csvs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(
7373

7474
self.filepath_or_buffer = path_or_buf
7575
self.encoding = encoding
76-
self.compression = compression
76+
self.compression: CompressionOptions = compression
7777
self.mode = mode
7878
self.storage_options = storage_options
7979

0 commit comments

Comments
 (0)