Skip to content

Commit e63e2af

Browse files
authored
CI: update autotyping (#52232)
* CI: update autotyping * isort
1 parent 34ee4fa commit e63e2af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+210
-172
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ repos:
413413
language: python
414414
stages: [manual]
415415
additional_dependencies:
416-
- autotyping==22.9.0
417-
- libcst==0.4.7
416+
- autotyping==23.3.0
417+
- libcst==0.4.9
418418
- id: check-test-naming
419419
name: check that test names start with 'test'
420420
entry: python -m scripts.check_test_naming

pandas/_config/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ def pp(name: str, ks: Iterable[str]) -> list[str]:
737737

738738

739739
@contextmanager
740-
def config_prefix(prefix) -> Generator[None, None, None]:
740+
def config_prefix(prefix: str) -> Generator[None, None, None]:
741741
"""
742742
contextmanager for multiple invocations of API with a common prefix
743743

pandas/_testing/_random.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
RANDS_CHARS = np.array(list(string.ascii_letters + string.digits), dtype=(np.str_, 1))
1111

1212

13-
def rands_array(nchars, size, dtype: NpDtype = "O", replace: bool = True) -> np.ndarray:
13+
def rands_array(
14+
nchars, size: int, dtype: NpDtype = "O", replace: bool = True
15+
) -> np.ndarray:
1416
"""
1517
Generate an array of byte strings.
1618
"""

pandas/_testing/contexts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def ensure_safe_environment_variables() -> Generator[None, None, None]:
154154

155155

156156
@contextmanager
157-
def with_csv_dialect(name, **kwargs) -> Generator[None, None, None]:
157+
def with_csv_dialect(name: str, **kwargs) -> Generator[None, None, None]:
158158
"""
159159
Context manager to temporarily register a CSV dialect for parsing CSV.
160160

pandas/compat/numpy/function.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def validate_take_with_convert(convert: ndarray | bool | None, args, kwargs) ->
342342
)
343343

344344

345-
def validate_groupby_func(name, args, kwargs, allowed=None) -> None:
345+
def validate_groupby_func(name: str, args, kwargs, allowed=None) -> None:
346346
"""
347347
'args' and 'kwargs' should be empty, except for allowed kwargs because all
348348
of their necessary parameters are explicitly listed in the function

pandas/core/accessor.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ class PandasDelegate:
5151
Abstract base class for delegating methods/properties.
5252
"""
5353

54-
def _delegate_property_get(self, name, *args, **kwargs):
54+
def _delegate_property_get(self, name: str, *args, **kwargs):
5555
raise TypeError(f"You cannot access the property {name}")
5656

57-
def _delegate_property_set(self, name, value, *args, **kwargs):
57+
def _delegate_property_set(self, name: str, value, *args, **kwargs):
5858
raise TypeError(f"The property {name} cannot be set")
5959

60-
def _delegate_method(self, name, *args, **kwargs):
60+
def _delegate_method(self, name: str, *args, **kwargs):
6161
raise TypeError(f"You cannot call method {name}")
6262

6363
@classmethod
@@ -91,7 +91,7 @@ def _add_delegate_accessors(
9191
False skips the missing accessor.
9292
"""
9393

94-
def _create_delegator_property(name):
94+
def _create_delegator_property(name: str):
9595
def _getter(self):
9696
return self._delegate_property_get(name)
9797

@@ -107,7 +107,7 @@ def _setter(self, new_values):
107107
doc=getattr(delegate, accessor_mapping(name)).__doc__,
108108
)
109109

110-
def _create_delegator_method(name):
110+
def _create_delegator_method(name: str):
111111
def f(self, *args, **kwargs):
112112
return self._delegate_method(name, *args, **kwargs)
113113

@@ -231,7 +231,7 @@ def __get__(self, obj, cls):
231231

232232

233233
@doc(klass="", others="")
234-
def _register_accessor(name, cls):
234+
def _register_accessor(name: str, cls):
235235
"""
236236
Register a custom accessor on {klass} objects.
237237
@@ -320,21 +320,21 @@ def decorator(accessor):
320320

321321

322322
@doc(_register_accessor, klass="DataFrame")
323-
def register_dataframe_accessor(name):
323+
def register_dataframe_accessor(name: str):
324324
from pandas import DataFrame
325325

326326
return _register_accessor(name, DataFrame)
327327

328328

329329
@doc(_register_accessor, klass="Series")
330-
def register_series_accessor(name):
330+
def register_series_accessor(name: str):
331331
from pandas import Series
332332

333333
return _register_accessor(name, Series)
334334

335335

336336
@doc(_register_accessor, klass="Index")
337-
def register_index_accessor(name):
337+
def register_index_accessor(name: str):
338338
from pandas import Index
339339

340340
return _register_accessor(name, Index)

pandas/core/arrays/_mixins.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,14 @@ def __getitem__(
291291
return result
292292

293293
def _fill_mask_inplace(
294-
self, method: str, limit, mask: npt.NDArray[np.bool_]
294+
self, method: str, limit: int | None, mask: npt.NDArray[np.bool_]
295295
) -> None:
296296
# (for now) when self.ndim == 2, we assume axis=0
297297
func = missing.get_fill_func(method, ndim=self.ndim)
298298
func(self._ndarray.T, limit=limit, mask=mask.T)
299299

300300
@doc(ExtensionArray.fillna)
301-
def fillna(self, value=None, method=None, limit=None) -> Self:
301+
def fillna(self, value=None, method=None, limit: int | None = None) -> Self:
302302
value, method = validate_fillna_kwargs(
303303
value, method, validate_scalar_dict_value=False
304304
)

pandas/core/arrays/arrow/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ def _str_translate(self, table):
19521952
"str.translate not supported with pd.ArrowDtype(pa.string())."
19531953
)
19541954

1955-
def _str_wrap(self, width, **kwargs):
1955+
def _str_wrap(self, width: int, **kwargs):
19561956
raise NotImplementedError(
19571957
"str.wrap not supported with pd.ArrowDtype(pa.string())."
19581958
)

pandas/core/arrays/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ def _where(self, mask: npt.NDArray[np.bool_], value) -> Self:
15701570
return result
15711571

15721572
def _fill_mask_inplace(
1573-
self, method: str, limit, mask: npt.NDArray[np.bool_]
1573+
self, method: str, limit: int | None, mask: npt.NDArray[np.bool_]
15741574
) -> None:
15751575
"""
15761576
Replace values in locations specified by 'mask' using pad or backfill.

pandas/core/arrays/categorical.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -2500,10 +2500,14 @@ def _validate(data):
25002500
if not is_categorical_dtype(data.dtype):
25012501
raise AttributeError("Can only use .cat accessor with a 'category' dtype")
25022502

2503-
def _delegate_property_get(self, name):
2503+
# error: Signature of "_delegate_property_get" incompatible with supertype
2504+
# "PandasDelegate"
2505+
def _delegate_property_get(self, name: str): # type: ignore[override]
25042506
return getattr(self._parent, name)
25052507

2506-
def _delegate_property_set(self, name, new_values):
2508+
# error: Signature of "_delegate_property_set" incompatible with supertype
2509+
# "PandasDelegate"
2510+
def _delegate_property_set(self, name: str, new_values): # type: ignore[override]
25072511
return setattr(self._parent, name, new_values)
25082512

25092513
@property
@@ -2515,7 +2519,7 @@ def codes(self) -> Series:
25152519

25162520
return Series(self._parent.codes, index=self._index)
25172521

2518-
def _delegate_method(self, name, *args, **kwargs):
2522+
def _delegate_method(self, name: str, *args, **kwargs):
25192523
from pandas import Series
25202524

25212525
method = getattr(self._parent, name)

pandas/core/arrays/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def tz_to_dtype(tz: tzinfo | None, unit: str = "ns"):
113113
return DatetimeTZDtype(tz=tz, unit=unit)
114114

115115

116-
def _field_accessor(name: str, field: str, docstring=None):
116+
def _field_accessor(name: str, field: str, docstring: str | None = None):
117117
def f(self):
118118
values = self._local_timestamps()
119119

pandas/core/arrays/interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ def max(self, *, axis: AxisInt | None = None, skipna: bool = True) -> IntervalOr
889889
indexer = obj.argsort()[-1]
890890
return obj[indexer]
891891

892-
def fillna(self, value=None, method=None, limit=None) -> Self:
892+
def fillna(self, value=None, method=None, limit: int | None = None) -> Self:
893893
"""
894894
Fill NA/NaN values using the specified method.
895895

pandas/core/arrays/masked.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def __getitem__(self, item: PositionalIndexer) -> Self | Any:
162162

163163
@doc(ExtensionArray.fillna)
164164
@doc(ExtensionArray.fillna)
165-
def fillna(self, value=None, method=None, limit=None) -> Self:
165+
def fillna(self, value=None, method=None, limit: int | None = None) -> Self:
166166
value, method = validate_fillna_kwargs(value, method)
167167

168168
mask = self._mask

pandas/core/arrays/period.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
}
9999

100100

101-
def _field_accessor(name: str, docstring=None):
101+
def _field_accessor(name: str, docstring: str | None = None):
102102
def f(self):
103103
base = self.freq._period_dtype_code
104104
result = get_period_field_arr(name, self.asi8, base)
@@ -658,7 +658,7 @@ def searchsorted(
658658
m8arr = self._ndarray.view("M8[ns]")
659659
return m8arr.searchsorted(npvalue, side=side, sorter=sorter)
660660

661-
def fillna(self, value=None, method=None, limit=None) -> PeriodArray:
661+
def fillna(self, value=None, method=None, limit: int | None = None) -> PeriodArray:
662662
if method is not None:
663663
# view as dt64 so we get treated as timelike in core.missing,
664664
# similar to dtl._period_dispatch

pandas/core/arrays/sparse/accessor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def _validate(self, data):
4646
if not isinstance(data.dtype, SparseDtype):
4747
raise AttributeError(self._validation_msg)
4848

49-
def _delegate_property_get(self, name, *args, **kwargs):
49+
def _delegate_property_get(self, name: str, *args, **kwargs):
5050
return getattr(self._parent.array, name)
5151

52-
def _delegate_method(self, name, *args, **kwargs):
52+
def _delegate_method(self, name: str, *args, **kwargs):
5353
if name == "from_coo":
5454
return self.from_coo(*args, **kwargs)
5555
elif name == "to_coo":

pandas/core/frame.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -4928,7 +4928,9 @@ def _series(self):
49284928
# ----------------------------------------------------------------------
49294929
# Reindexing and alignment
49304930

4931-
def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy):
4931+
def _reindex_axes(
4932+
self, axes, level, limit: int | None, tolerance, method, fill_value, copy
4933+
):
49324934
frame = self
49334935

49344936
columns = axes["columns"]
@@ -4952,7 +4954,7 @@ def _reindex_index(
49524954
copy: bool,
49534955
level: Level,
49544956
fill_value=np.nan,
4955-
limit=None,
4957+
limit: int | None = None,
49564958
tolerance=None,
49574959
):
49584960
new_index, indexer = self.index.reindex(
@@ -4972,7 +4974,7 @@ def _reindex_columns(
49724974
copy: bool,
49734975
level: Level,
49744976
fill_value=None,
4975-
limit=None,
4977+
limit: int | None = None,
49764978
tolerance=None,
49774979
):
49784980
new_columns, indexer = self.columns.reindex(

pandas/core/generic.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
255255
_accessors: set[str] = set()
256256
_hidden_attrs: frozenset[str] = frozenset([])
257257
_metadata: list[str] = []
258-
_is_copy: weakref.ReferenceType[NDFrame] | None = None
258+
_is_copy: weakref.ReferenceType[NDFrame] | str | None = None
259259
_mgr: Manager
260260
_attrs: dict[Hashable, Any]
261261
_typ: str
@@ -4325,7 +4325,7 @@ def __delitem__(self, key) -> None:
43254325
# Unsorted
43264326

43274327
@final
4328-
def _check_inplace_and_allows_duplicate_labels(self, inplace):
4328+
def _check_inplace_and_allows_duplicate_labels(self, inplace: bool_t):
43294329
if inplace and not self.flags.allows_duplicate_labels:
43304330
raise ValueError(
43314331
"Cannot specify 'inplace=True' when "
@@ -4403,7 +4403,7 @@ def reindex_like(
44034403
other,
44044404
method: Literal["backfill", "bfill", "pad", "ffill", "nearest"] | None = None,
44054405
copy: bool_t | None = None,
4406-
limit=None,
4406+
limit: int | None = None,
44074407
tolerance=None,
44084408
) -> Self:
44094409
"""
@@ -9647,7 +9647,7 @@ def _align_frame(
96479647
copy: bool_t | None = None,
96489648
fill_value=None,
96499649
method=None,
9650-
limit=None,
9650+
limit: int | None = None,
96519651
fill_axis: Axis = 0,
96529652
) -> tuple[Self, DataFrame, Index | None]:
96539653
# defaults
@@ -9703,7 +9703,7 @@ def _align_series(
97039703
copy: bool_t | None = None,
97049704
fill_value=None,
97059705
method=None,
9706-
limit=None,
9706+
limit: int | None = None,
97079707
fill_axis: Axis = 0,
97089708
) -> tuple[Self, Series, Index | None]:
97099709
is_series = isinstance(self, ABCSeries)
@@ -11002,7 +11002,7 @@ def pct_change(
1100211002
self,
1100311003
periods: int = 1,
1100411004
fill_method: Literal["backfill", "bfill", "pad", "ffill"] | None = "pad",
11005-
limit=None,
11005+
limit: int | None = None,
1100611006
freq=None,
1100711007
**kwargs,
1100811008
) -> Self:

pandas/core/groupby/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ def fillna(
22492249
method: FillnaOptions | None = None,
22502250
axis: Axis | None | lib.NoDefault = lib.no_default,
22512251
inplace: bool = False,
2252-
limit=None,
2252+
limit: int | None = None,
22532253
downcast=None,
22542254
) -> DataFrame | None:
22552255
"""

pandas/core/groupby/groupby.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,7 @@ def ewm(self, *args, **kwargs) -> ExponentialMovingWindowGroupby:
27812781
)
27822782

27832783
@final
2784-
def _fill(self, direction: Literal["ffill", "bfill"], limit=None):
2784+
def _fill(self, direction: Literal["ffill", "bfill"], limit: int | None = None):
27852785
"""
27862786
Shared function for `pad` and `backfill` to call Cython method.
27872787
@@ -2868,7 +2868,7 @@ def blk_func(values: ArrayLike) -> ArrayLike:
28682868

28692869
@final
28702870
@Substitution(name="groupby")
2871-
def ffill(self, limit=None):
2871+
def ffill(self, limit: int | None = None):
28722872
"""
28732873
Forward fill the values.
28742874
@@ -2893,7 +2893,7 @@ def ffill(self, limit=None):
28932893

28942894
@final
28952895
@Substitution(name="groupby")
2896-
def bfill(self, limit=None):
2896+
def bfill(self, limit: int | None = None):
28972897
"""
28982898
Backward fill the values.
28992899
@@ -3789,7 +3789,7 @@ def pct_change(
37893789
self,
37903790
periods: int = 1,
37913791
fill_method: FillnaOptions = "ffill",
3792-
limit=None,
3792+
limit: int | None = None,
37933793
freq=None,
37943794
axis: Axis | lib.NoDefault = lib.no_default,
37953795
):

pandas/core/indexes/accessors.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ def _get_values(self):
8181
f"cannot convert an object of type {type(data)} to a datetimelike index"
8282
)
8383

84-
def _delegate_property_get(self, name):
84+
# error: Signature of "_delegate_property_get" incompatible with supertype
85+
# "PandasDelegate"
86+
def _delegate_property_get(self, name: str): # type: ignore[override]
8587
from pandas import Series
8688

8789
values = self._get_values()
@@ -113,13 +115,13 @@ def _delegate_property_get(self, name):
113115

114116
return result
115117

116-
def _delegate_property_set(self, name, value, *args, **kwargs):
118+
def _delegate_property_set(self, name: str, value, *args, **kwargs):
117119
raise ValueError(
118120
"modifications to a property of a datetimelike object are not supported. "
119121
"Change values on the original."
120122
)
121123

122-
def _delegate_method(self, name, *args, **kwargs):
124+
def _delegate_method(self, name: str, *args, **kwargs):
123125
from pandas import Series
124126

125127
values = self._get_values()

0 commit comments

Comments
 (0)