diff --git a/environment.yml b/environment.yml index a22229b812d23..3e5b73d2cca0b 100644 --- a/environment.yml +++ b/environment.yml @@ -91,6 +91,9 @@ dependencies: - sphinx - sphinx-design - sphinx-copybutton + + # static typing + - scipy-stubs - types-python-dateutil - types-PyMySQL - types-pytz diff --git a/pandas/core/missing.py b/pandas/core/missing.py index ff6dc5ad29fd2..141ec5df76792 100644 --- a/pandas/core/missing.py +++ b/pandas/core/missing.py @@ -45,6 +45,7 @@ ) if TYPE_CHECKING: + from collections.abc import Callable from typing import TypeAlias from pandas import Index @@ -548,7 +549,7 @@ def _interpolate_scipy_wrapper( new_x = np.asarray(new_x) # ignores some kwargs that could be passed along. - alt_methods = { + alt_methods: dict[str, Callable[..., np.ndarray]] = { "barycentric": interpolate.barycentric_interpolate, "krogh": interpolate.krogh_interpolate, "from_derivatives": _from_derivatives, @@ -566,6 +567,7 @@ def _interpolate_scipy_wrapper( "cubic", "polynomial", ] + terp: Callable[..., np.ndarray] | None if method in interp1d_methods: if method == "polynomial": kind = order diff --git a/pandas/plotting/_matplotlib/hist.py b/pandas/plotting/_matplotlib/hist.py index 1a423ad49c294..ae2e666bf5f1a 100644 --- a/pandas/plotting/_matplotlib/hist.py +++ b/pandas/plotting/_matplotlib/hist.py @@ -260,7 +260,7 @@ def _get_ind(y: np.ndarray, ind): @classmethod # error: Signature of "_plot" incompatible with supertype "MPLPlot" - def _plot( # type: ignore[override] + def _plot( # type: ignore[override] cls, ax: Axes, y: np.ndarray, @@ -277,6 +277,8 @@ def _plot( # type: ignore[override] y = remove_na_arraylike(y) gkde = gaussian_kde(y, bw_method=bw_method, weights=weights) + # gaussian_kde.evaluate(None) raises TypeError, so pyright requires this check + assert ind is not None y = gkde.evaluate(ind) lines = MPLPlot._plot(ax, ind, y, style=style, **kwds) return lines diff --git a/requirements-dev.txt b/requirements-dev.txt index 721f094c052e3..c799fe3d2f076 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -66,6 +66,7 @@ pytest-cython sphinx sphinx-design sphinx-copybutton +scipy-stubs types-python-dateutil types-PyMySQL types-pytz