Skip to content

CI: update autotyping #52232

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 2 commits into from
Mar 27, 2023
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ repos:
language: python
stages: [manual]
additional_dependencies:
- autotyping==22.9.0
- libcst==0.4.7
- autotyping==23.3.0
- libcst==0.4.9
- id: check-test-naming
name: check that test names start with 'test'
entry: python -m scripts.check_test_naming
Expand Down
2 changes: 1 addition & 1 deletion pandas/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def pp(name: str, ks: Iterable[str]) -> list[str]:


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

Expand Down
4 changes: 3 additions & 1 deletion pandas/_testing/_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
RANDS_CHARS = np.array(list(string.ascii_letters + string.digits), dtype=(np.str_, 1))


def rands_array(nchars, size, dtype: NpDtype = "O", replace: bool = True) -> np.ndarray:
def rands_array(
nchars, size: int, dtype: NpDtype = "O", replace: bool = True
) -> np.ndarray:
"""
Generate an array of byte strings.
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/_testing/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def ensure_safe_environment_variables() -> Generator[None, None, None]:


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

Expand Down
2 changes: 1 addition & 1 deletion pandas/compat/numpy/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def validate_take_with_convert(convert: ndarray | bool | None, args, kwargs) ->
)


def validate_groupby_func(name, args, kwargs, allowed=None) -> None:
def validate_groupby_func(name: str, args, kwargs, allowed=None) -> None:
"""
'args' and 'kwargs' should be empty, except for allowed kwargs because all
of their necessary parameters are explicitly listed in the function
Expand Down
18 changes: 9 additions & 9 deletions pandas/core/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ class PandasDelegate:
Abstract base class for delegating methods/properties.
"""

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

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

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

@classmethod
Expand Down Expand Up @@ -91,7 +91,7 @@ def _add_delegate_accessors(
False skips the missing accessor.
"""

def _create_delegator_property(name):
def _create_delegator_property(name: str):
def _getter(self):
return self._delegate_property_get(name)

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

def _create_delegator_method(name):
def _create_delegator_method(name: str):
def f(self, *args, **kwargs):
return self._delegate_method(name, *args, **kwargs)

Expand Down Expand Up @@ -231,7 +231,7 @@ def __get__(self, obj, cls):


@doc(klass="", others="")
def _register_accessor(name, cls):
def _register_accessor(name: str, cls):
"""
Register a custom accessor on {klass} objects.

Expand Down Expand Up @@ -320,21 +320,21 @@ def decorator(accessor):


@doc(_register_accessor, klass="DataFrame")
def register_dataframe_accessor(name):
def register_dataframe_accessor(name: str):
from pandas import DataFrame

return _register_accessor(name, DataFrame)


@doc(_register_accessor, klass="Series")
def register_series_accessor(name):
def register_series_accessor(name: str):
from pandas import Series

return _register_accessor(name, Series)


@doc(_register_accessor, klass="Index")
def register_index_accessor(name):
def register_index_accessor(name: str):
from pandas import Index

return _register_accessor(name, Index)
4 changes: 2 additions & 2 deletions pandas/core/arrays/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,14 @@ def __getitem__(
return result

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

@doc(ExtensionArray.fillna)
def fillna(self, value=None, method=None, limit=None) -> Self:
def fillna(self, value=None, method=None, limit: int | None = None) -> Self:
value, method = validate_fillna_kwargs(
value, method, validate_scalar_dict_value=False
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ def _str_translate(self, table):
"str.translate not supported with pd.ArrowDtype(pa.string())."
)

def _str_wrap(self, width, **kwargs):
def _str_wrap(self, width: int, **kwargs):
raise NotImplementedError(
"str.wrap not supported with pd.ArrowDtype(pa.string())."
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ def _where(self, mask: npt.NDArray[np.bool_], value) -> Self:
return result

def _fill_mask_inplace(
self, method: str, limit, mask: npt.NDArray[np.bool_]
self, method: str, limit: int | None, mask: npt.NDArray[np.bool_]
) -> None:
"""
Replace values in locations specified by 'mask' using pad or backfill.
Expand Down
10 changes: 7 additions & 3 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2500,10 +2500,14 @@ def _validate(data):
if not is_categorical_dtype(data.dtype):
raise AttributeError("Can only use .cat accessor with a 'category' dtype")

def _delegate_property_get(self, name):
# error: Signature of "_delegate_property_get" incompatible with supertype
# "PandasDelegate"
def _delegate_property_get(self, name: str): # type: ignore[override]
return getattr(self._parent, name)

def _delegate_property_set(self, name, new_values):
# error: Signature of "_delegate_property_set" incompatible with supertype
# "PandasDelegate"
def _delegate_property_set(self, name: str, new_values): # type: ignore[override]
return setattr(self._parent, name, new_values)

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

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

def _delegate_method(self, name, *args, **kwargs):
def _delegate_method(self, name: str, *args, **kwargs):
from pandas import Series

method = getattr(self._parent, name)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def tz_to_dtype(tz: tzinfo | None, unit: str = "ns"):
return DatetimeTZDtype(tz=tz, unit=unit)


def _field_accessor(name: str, field: str, docstring=None):
def _field_accessor(name: str, field: str, docstring: str | None = None):
def f(self):
values = self._local_timestamps()

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ def max(self, *, axis: AxisInt | None = None, skipna: bool = True) -> IntervalOr
indexer = obj.argsort()[-1]
return obj[indexer]

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

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __getitem__(self, item: PositionalIndexer) -> Self | Any:

@doc(ExtensionArray.fillna)
@doc(ExtensionArray.fillna)
def fillna(self, value=None, method=None, limit=None) -> Self:
def fillna(self, value=None, method=None, limit: int | None = None) -> Self:
value, method = validate_fillna_kwargs(value, method)

mask = self._mask
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
}


def _field_accessor(name: str, docstring=None):
def _field_accessor(name: str, docstring: str | None = None):
def f(self):
base = self.freq._period_dtype_code
result = get_period_field_arr(name, self.asi8, base)
Expand Down Expand Up @@ -658,7 +658,7 @@ def searchsorted(
m8arr = self._ndarray.view("M8[ns]")
return m8arr.searchsorted(npvalue, side=side, sorter=sorter)

def fillna(self, value=None, method=None, limit=None) -> PeriodArray:
def fillna(self, value=None, method=None, limit: int | None = None) -> PeriodArray:
if method is not None:
# view as dt64 so we get treated as timelike in core.missing,
# similar to dtl._period_dispatch
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/sparse/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def _validate(self, data):
if not isinstance(data.dtype, SparseDtype):
raise AttributeError(self._validation_msg)

def _delegate_property_get(self, name, *args, **kwargs):
def _delegate_property_get(self, name: str, *args, **kwargs):
return getattr(self._parent.array, name)

def _delegate_method(self, name, *args, **kwargs):
def _delegate_method(self, name: str, *args, **kwargs):
if name == "from_coo":
return self.from_coo(*args, **kwargs)
elif name == "to_coo":
Expand Down
8 changes: 5 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4936,7 +4936,9 @@ def _series(self):
# ----------------------------------------------------------------------
# Reindexing and alignment

def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy):
def _reindex_axes(
self, axes, level, limit: int | None, tolerance, method, fill_value, copy
):
frame = self

columns = axes["columns"]
Expand All @@ -4960,7 +4962,7 @@ def _reindex_index(
copy: bool,
level: Level,
fill_value=np.nan,
limit=None,
limit: int | None = None,
tolerance=None,
):
new_index, indexer = self.index.reindex(
Expand All @@ -4980,7 +4982,7 @@ def _reindex_columns(
copy: bool,
level: Level,
fill_value=None,
limit=None,
limit: int | None = None,
tolerance=None,
):
new_columns, indexer = self.columns.reindex(
Expand Down
12 changes: 6 additions & 6 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
_accessors: set[str] = set()
_hidden_attrs: frozenset[str] = frozenset([])
_metadata: list[str] = []
_is_copy: weakref.ReferenceType[NDFrame] | None = None
_is_copy: weakref.ReferenceType[NDFrame] | str | None = None
_mgr: Manager
_attrs: dict[Hashable, Any]
_typ: str
Expand Down Expand Up @@ -4306,7 +4306,7 @@ def __delitem__(self, key) -> None:
# Unsorted

@final
def _check_inplace_and_allows_duplicate_labels(self, inplace):
def _check_inplace_and_allows_duplicate_labels(self, inplace: bool_t):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was bool, had to change it to bool_t

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's what I meant, I presume the other hook caught this one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy made me change it :)

if inplace and not self.flags.allows_duplicate_labels:
raise ValueError(
"Cannot specify 'inplace=True' when "
Expand Down Expand Up @@ -4384,7 +4384,7 @@ def reindex_like(
other,
method: Literal["backfill", "bfill", "pad", "ffill", "nearest"] | None = None,
copy: bool_t | None = None,
limit=None,
limit: int | None = None,
tolerance=None,
) -> Self:
"""
Expand Down Expand Up @@ -9628,7 +9628,7 @@ def _align_frame(
copy: bool_t | None = None,
fill_value=None,
method=None,
limit=None,
limit: int | None = None,
fill_axis: Axis = 0,
) -> tuple[Self, DataFrame, Index | None]:
# defaults
Expand Down Expand Up @@ -9684,7 +9684,7 @@ def _align_series(
copy: bool_t | None = None,
fill_value=None,
method=None,
limit=None,
limit: int | None = None,
fill_axis: Axis = 0,
) -> tuple[Self, Series, Index | None]:
is_series = isinstance(self, ABCSeries)
Expand Down Expand Up @@ -10983,7 +10983,7 @@ def pct_change(
self,
periods: int = 1,
fill_method: Literal["backfill", "bfill", "pad", "ffill"] | None = "pad",
limit=None,
limit: int | None = None,
freq=None,
**kwargs,
) -> Self:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2249,7 +2249,7 @@ def fillna(
method: FillnaOptions | None = None,
axis: Axis | None | lib.NoDefault = lib.no_default,
inplace: bool = False,
limit=None,
limit: int | None = None,
downcast=None,
) -> DataFrame | None:
"""
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2781,7 +2781,7 @@ def ewm(self, *args, **kwargs) -> ExponentialMovingWindowGroupby:
)

@final
def _fill(self, direction: Literal["ffill", "bfill"], limit=None):
def _fill(self, direction: Literal["ffill", "bfill"], limit: int | None = None):
"""
Shared function for `pad` and `backfill` to call Cython method.

Expand Down Expand Up @@ -2868,7 +2868,7 @@ def blk_func(values: ArrayLike) -> ArrayLike:

@final
@Substitution(name="groupby")
def ffill(self, limit=None):
def ffill(self, limit: int | None = None):
"""
Forward fill the values.

Expand All @@ -2893,7 +2893,7 @@ def ffill(self, limit=None):

@final
@Substitution(name="groupby")
def bfill(self, limit=None):
def bfill(self, limit: int | None = None):
"""
Backward fill the values.

Expand Down Expand Up @@ -3789,7 +3789,7 @@ def pct_change(
self,
periods: int = 1,
fill_method: FillnaOptions = "ffill",
limit=None,
limit: int | None = None,
freq=None,
axis: Axis | lib.NoDefault = lib.no_default,
):
Expand Down
8 changes: 5 additions & 3 deletions pandas/core/indexes/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def _get_values(self):
f"cannot convert an object of type {type(data)} to a datetimelike index"
)

def _delegate_property_get(self, name):
# error: Signature of "_delegate_property_get" incompatible with supertype
# "PandasDelegate"
def _delegate_property_get(self, name: str): # type: ignore[override]
from pandas import Series

values = self._get_values()
Expand Down Expand Up @@ -113,13 +115,13 @@ def _delegate_property_get(self, name):

return result

def _delegate_property_set(self, name, value, *args, **kwargs):
def _delegate_property_set(self, name: str, value, *args, **kwargs):
raise ValueError(
"modifications to a property of a datetimelike object are not supported. "
"Change values on the original."
)

def _delegate_method(self, name, *args, **kwargs):
def _delegate_method(self, name: str, *args, **kwargs):
from pandas import Series

values = self._get_values()
Expand Down
Loading