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

13 files changed

+36
-39
lines changed

pandas/compat/pickle_compat.py

+1-1
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

+3-3
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

+13-5
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

+7-7
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

+1-1
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

+2-2
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

+1-1
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

+1-1
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

+2-2
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

+3-3
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())

pandas/util/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ def __getattr__(key: str):
2525
raise AttributeError(f"module 'pandas.util' has no attribute '{key}'")
2626

2727

28-
def __dir__():
28+
def __dir__() -> list[str]:
2929
return list(globals().keys()) + ["hash_array", "hash_pandas_object"]

pandas/util/_print_versions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _get_commit_hash() -> str | None:
3333
except ImportError:
3434
from pandas._version import get_versions
3535

36-
versions = get_versions()
36+
versions = get_versions() # type: ignore[no-untyped-call]
3737
return versions["full-revisionid"]
3838

3939

pyproject.toml

-11
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,9 @@ module = [
567567
"pandas._config.config", # TODO
568568
"pandas._libs.*",
569569
"pandas._testing.*", # TODO
570-
"pandas.arrays", # TODO
571570
"pandas.compat.numpy.function", # TODO
572571
"pandas.compat.compressors", # TODO
573-
"pandas.compat.pickle_compat", # TODO
574572
"pandas.core._numba.executor", # TODO
575-
"pandas.core.array_algos.datetimelike_accumulations", # TODO
576-
"pandas.core.array_algos.masked_accumulations", # TODO
577573
"pandas.core.array_algos.masked_reductions", # TODO
578574
"pandas.core.array_algos.putmask", # TODO
579575
"pandas.core.array_algos.quantile", # TODO
@@ -588,7 +584,6 @@ module = [
588584
"pandas.core.dtypes.dtypes", # TODO
589585
"pandas.core.dtypes.generic", # TODO
590586
"pandas.core.dtypes.missing", # TODO
591-
"pandas.core.groupby.categorical", # TODO
592587
"pandas.core.groupby.generic", # TODO
593588
"pandas.core.groupby.grouper", # TODO
594589
"pandas.core.groupby.groupby", # TODO
@@ -603,7 +598,6 @@ module = [
603598
"pandas.core.ops.array_ops", # TODO
604599
"pandas.core.ops.common", # TODO
605600
"pandas.core.ops.invalid", # TODO
606-
"pandas.core.ops.mask_ops", # TODO
607601
"pandas.core.ops.missing", # TODO
608602
"pandas.core.reshape.*", # TODO
609603
"pandas.core.strings.*", # TODO
@@ -620,7 +614,6 @@ module = [
620614
"pandas.core.arraylike", # TODO
621615
"pandas.core.base", # TODO
622616
"pandas.core.common", # TODO
623-
"pandas.core.config_init", # TODO
624617
"pandas.core.construction", # TODO
625618
"pandas.core.flags", # TODO
626619
"pandas.core.frame", # TODO
@@ -642,11 +635,9 @@ module = [
642635
"pandas.io.excel._pyxlsb", # TODO
643636
"pandas.io.excel._xlrd", # TODO
644637
"pandas.io.excel._xlsxwriter", # TODO
645-
"pandas.io.formats.console", # TODO
646638
"pandas.io.formats.css", # TODO
647639
"pandas.io.formats.excel", # TODO
648640
"pandas.io.formats.format", # TODO
649-
"pandas.io.formats.info", # TODO
650641
"pandas.io.formats.printing", # TODO
651642
"pandas.io.formats.style", # TODO
652643
"pandas.io.formats.style_render", # TODO
@@ -661,15 +652,13 @@ module = [
661652
"pandas.io.parquet", # TODO
662653
"pandas.io.pytables", # TODO
663654
"pandas.io.sql", # TODO
664-
"pandas.io.stata", # TODO
665655
"pandas.io.xml", # TODO
666656
"pandas.plotting.*", # TODO
667657
"pandas.tests.*",
668658
"pandas.tseries.frequencies", # TODO
669659
"pandas.tseries.holiday", # TODO
670660
"pandas.util._decorators", # TODO
671661
"pandas.util._doctools", # TODO
672-
"pandas.util._print_versions", # TODO
673662
"pandas.util._test_decorators", # TODO
674663
"pandas.util._validators", # TODO
675664
"pandas.util", # TODO

0 commit comments

Comments
 (0)