Skip to content

Commit 0cc12bc

Browse files
authored
Fix some typing errors (#57795)
* Fix some typing errors * Fix some typing errors * Fix some typing errors * Fix some typing errors * Fix some typing errors * Fix some typing errors * Fix some typing errors * Fix some typing errors * Fix some typing errors * Fix some typing errors * Fix some typing errors * Fix some typing errors * Review * Review
1 parent dc19148 commit 0cc12bc

File tree

13 files changed

+36
-39
lines changed

13 files changed

+36
-39
lines changed

pandas/compat/pickle_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
# our Unpickler sub-class to override methods and some dispatcher
6565
# functions for compat and uses a non-public class of the pickle module.
6666
class Unpickler(pickle._Unpickler):
67-
def find_class(self, module, name):
67+
def find_class(self, module: str, name: str) -> Any:
6868
key = (module, name)
6969
module, name = _class_locations_map.get(key, key)
7070
return super().find_class(module, name)

pandas/core/array_algos/datetimelike_accumulations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def _cum_func(
1818
values: np.ndarray,
1919
*,
2020
skipna: bool = True,
21-
):
21+
) -> np.ndarray:
2222
"""
2323
Accumulations for 1D datetimelike arrays.
2424
@@ -61,9 +61,9 @@ def cumsum(values: np.ndarray, *, skipna: bool = True) -> np.ndarray:
6161
return _cum_func(np.cumsum, values, skipna=skipna)
6262

6363

64-
def cummin(values: np.ndarray, *, skipna: bool = True):
64+
def cummin(values: np.ndarray, *, skipna: bool = True) -> np.ndarray:
6565
return _cum_func(np.minimum.accumulate, values, skipna=skipna)
6666

6767

68-
def cummax(values: np.ndarray, *, skipna: bool = True):
68+
def cummax(values: np.ndarray, *, skipna: bool = True) -> np.ndarray:
6969
return _cum_func(np.maximum.accumulate, values, skipna=skipna)

pandas/core/array_algos/masked_accumulations.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _cum_func(
2222
mask: npt.NDArray[np.bool_],
2323
*,
2424
skipna: bool = True,
25-
):
25+
) -> tuple[np.ndarray, npt.NDArray[np.bool_]]:
2626
"""
2727
Accumulations for 1D masked array.
2828
@@ -74,17 +74,25 @@ def _cum_func(
7474
return values, mask
7575

7676

77-
def cumsum(values: np.ndarray, mask: npt.NDArray[np.bool_], *, skipna: bool = True):
77+
def cumsum(
78+
values: np.ndarray, mask: npt.NDArray[np.bool_], *, skipna: bool = True
79+
) -> tuple[np.ndarray, npt.NDArray[np.bool_]]:
7880
return _cum_func(np.cumsum, values, mask, skipna=skipna)
7981

8082

81-
def cumprod(values: np.ndarray, mask: npt.NDArray[np.bool_], *, skipna: bool = True):
83+
def cumprod(
84+
values: np.ndarray, mask: npt.NDArray[np.bool_], *, skipna: bool = True
85+
) -> tuple[np.ndarray, npt.NDArray[np.bool_]]:
8286
return _cum_func(np.cumprod, values, mask, skipna=skipna)
8387

8488

85-
def cummin(values: np.ndarray, mask: npt.NDArray[np.bool_], *, skipna: bool = True):
89+
def cummin(
90+
values: np.ndarray, mask: npt.NDArray[np.bool_], *, skipna: bool = True
91+
) -> tuple[np.ndarray, npt.NDArray[np.bool_]]:
8692
return _cum_func(np.minimum.accumulate, values, mask, skipna=skipna)
8793

8894

89-
def cummax(values: np.ndarray, mask: npt.NDArray[np.bool_], *, skipna: bool = True):
95+
def cummax(
96+
values: np.ndarray, mask: npt.NDArray[np.bool_], *, skipna: bool = True
97+
) -> tuple[np.ndarray, npt.NDArray[np.bool_]]:
9098
return _cum_func(np.maximum.accumulate, values, mask, skipna=skipna)

pandas/core/config_init.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"""
3838

3939

40-
def use_bottleneck_cb(key) -> None:
40+
def use_bottleneck_cb(key: str) -> None:
4141
from pandas.core import nanops
4242

4343
nanops.set_use_bottleneck(cf.get_option(key))
@@ -51,7 +51,7 @@ def use_bottleneck_cb(key) -> None:
5151
"""
5252

5353

54-
def use_numexpr_cb(key) -> None:
54+
def use_numexpr_cb(key: str) -> None:
5555
from pandas.core.computation import expressions
5656

5757
expressions.set_use_numexpr(cf.get_option(key))
@@ -65,7 +65,7 @@ def use_numexpr_cb(key) -> None:
6565
"""
6666

6767

68-
def use_numba_cb(key) -> None:
68+
def use_numba_cb(key: str) -> None:
6969
from pandas.core.util import numba_
7070

7171
numba_.set_use_numba(cf.get_option(key))
@@ -287,7 +287,7 @@ def use_numba_cb(key) -> None:
287287
"""
288288

289289

290-
def table_schema_cb(key) -> None:
290+
def table_schema_cb(key: str) -> None:
291291
from pandas.io.formats.printing import enable_data_resource_formatter
292292

293293
enable_data_resource_formatter(cf.get_option(key))
@@ -612,7 +612,7 @@ def is_terminal() -> bool:
612612
"""
613613

614614

615-
def register_plotting_backend_cb(key) -> None:
615+
def register_plotting_backend_cb(key: str | None) -> None:
616616
if key == "matplotlib":
617617
# We defer matplotlib validation, since it's the default
618618
return
@@ -626,7 +626,7 @@ def register_plotting_backend_cb(key) -> None:
626626
"backend",
627627
defval="matplotlib",
628628
doc=plotting_backend_doc,
629-
validator=register_plotting_backend_cb,
629+
validator=register_plotting_backend_cb, # type: ignore[arg-type]
630630
)
631631

632632

@@ -638,7 +638,7 @@ def register_plotting_backend_cb(key) -> None:
638638
"""
639639

640640

641-
def register_converter_cb(key) -> None:
641+
def register_converter_cb(key: str) -> None:
642642
from pandas.plotting import (
643643
deregister_matplotlib_converters,
644644
register_matplotlib_converters,

pandas/core/dtypes/concat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
)
4343

4444

45-
def _is_nonempty(x, axis) -> bool:
45+
def _is_nonempty(x: ArrayLike, axis: AxisInt) -> bool:
4646
# filter empty arrays
4747
# 1-d dtypes always are included here
4848
if x.ndim <= axis:

pandas/core/groupby/categorical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def recode_for_groupby(
5050
# In cases with c.ordered, this is equivalent to
5151
# return c.remove_unused_categories(), c
5252

53-
unique_codes = unique1d(c.codes)
53+
unique_codes = unique1d(c.codes) # type: ignore[no-untyped-call]
5454

5555
take_codes = unique_codes[unique_codes != -1]
5656
if sort:
@@ -74,7 +74,7 @@ def recode_for_groupby(
7474
# xref GH:46909: Re-ordering codes faster than using (set|add|reorder)_categories
7575
all_codes = np.arange(c.categories.nunique())
7676
# GH 38140: exclude nan from indexer for categories
77-
unique_notnan_codes = unique1d(c.codes[c.codes != -1])
77+
unique_notnan_codes = unique1d(c.codes[c.codes != -1]) # type: ignore[no-untyped-call]
7878
if sort:
7979
unique_notnan_codes = np.sort(unique_notnan_codes)
8080
if len(all_codes) > len(unique_notnan_codes):

pandas/core/ops/mask_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,6 @@ def kleene_and(
190190
return result, mask
191191

192192

193-
def raise_for_nan(value, method: str) -> None:
193+
def raise_for_nan(value: object, method: str) -> None:
194194
if lib.is_float(value) and np.isnan(value):
195195
raise ValueError(f"Cannot perform logical '{method}' with floating NaN")

pandas/io/formats/console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def in_interactive_session() -> bool:
6363
"""
6464
from pandas import get_option
6565

66-
def check_main():
66+
def check_main() -> bool:
6767
try:
6868
import __main__ as main
6969
except ModuleNotFoundError:

pandas/io/formats/css.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _side_expander(prop_fmt: str) -> Callable:
3636
function: Return to call when a 'border(-{side}): {value}' string is encountered
3737
"""
3838

39-
def expand(self, prop, value: str) -> Generator[tuple[str, str], None, None]:
39+
def expand(self, prop: str, value: str) -> Generator[tuple[str, str], None, None]:
4040
"""
4141
Expand shorthand property into side-specific property (top, right, bottom, left)
4242
@@ -81,7 +81,7 @@ def _border_expander(side: str = "") -> Callable:
8181
if side != "":
8282
side = f"-{side}"
8383

84-
def expand(self, prop, value: str) -> Generator[tuple[str, str], None, None]:
84+
def expand(self, prop: str, value: str) -> Generator[tuple[str, str], None, None]:
8585
"""
8686
Expand border into color, style, and width tuples
8787

pandas/io/stata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,7 @@ def _do_select_columns(self, data: DataFrame, columns: Sequence[str]) -> DataFra
18351835
fmtlist = []
18361836
lbllist = []
18371837
for col in columns:
1838-
i = data.columns.get_loc(col)
1838+
i = data.columns.get_loc(col) # type: ignore[no-untyped-call]
18391839
dtyplist.append(self._dtyplist[i])
18401840
typlist.append(self._typlist[i])
18411841
fmtlist.append(self._fmtlist[i])
@@ -2155,7 +2155,7 @@ def _dtype_to_stata_type(dtype: np.dtype, column: Series) -> int:
21552155

21562156

21572157
def _dtype_to_default_stata_fmt(
2158-
dtype, column: Series, dta_version: int = 114, force_strl: bool = False
2158+
dtype: np.dtype, column: Series, dta_version: int = 114, force_strl: bool = False
21592159
) -> str:
21602160
"""
21612161
Map numpy dtype to stata's default format for this type. Not terribly
@@ -3467,7 +3467,7 @@ def _write_characteristics(self) -> None:
34673467
self._update_map("characteristics")
34683468
self._write_bytes(self._tag(b"", "characteristics"))
34693469

3470-
def _write_data(self, records) -> None:
3470+
def _write_data(self, records: np.rec.recarray) -> None:
34713471
self._update_map("data")
34723472
self._write_bytes(b"<data>")
34733473
self._write_bytes(records.tobytes())

0 commit comments

Comments
 (0)