Skip to content

Commit

Permalink
TYP: Fix new static typing failures
Browse files Browse the repository at this point in the history
  • Loading branch information
has2k1 committed Dec 10, 2024
1 parent d45cdba commit 7b9c78c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions plotnine/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ def len_unique(x):
if drop:
return _id_var(res, drop)
else:
return list(res)
return res


def _id_var(x: pd.Series[Any], drop: bool = False) -> list[int]:
def _id_var(x: AnyArrayLike, drop: bool = False) -> list[int]:
"""
Assign ids to items in x. If two items
are the same, they get the same id.
Expand All @@ -334,7 +334,7 @@ def _id_var(x: pd.Series[Any], drop: bool = False) -> list[int]:
if len(x) == 0:
return []

if array_kind.categorical(x):
if isinstance(x, pd.Series) and array_kind.categorical(x):
if drop:
x = x.cat.remove_unused_categories()
lst = list(x.cat.codes + 1)
Expand Down
2 changes: 1 addition & 1 deletion plotnine/facets/facet.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def make_figure(self) -> tuple[Figure, list[Axes]]:
# Create axes
it = itertools.product(range(self.nrow), range(self.ncol))
for i, (row, col) in enumerate(it):
axsarr[row, col] = figure.add_subplot(gs[i])
axsarr[row, col] = figure.add_subplot(gs[i]) # pyright: ignore[reportCallIssue,reportArgumentType]

# axsarr = np.array([
# figure.add_subplot(gs[i])
Expand Down
11 changes: 6 additions & 5 deletions plotnine/geoms/geom_path.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import typing
from collections import Counter
from contextlib import suppress
from typing import TYPE_CHECKING
from warnings import warn

import numpy as np
Expand All @@ -12,7 +12,7 @@
from ..exceptions import PlotnineWarning
from .geom import geom

if typing.TYPE_CHECKING:
if TYPE_CHECKING:
from typing import Any, Literal, Sequence

import numpy.typing as npt
Expand All @@ -24,6 +24,7 @@
from plotnine.coords.coord import coord
from plotnine.iapi import panel_view
from plotnine.layer import layer
from plotnine.typing import BoolArray


@document
Expand Down Expand Up @@ -66,7 +67,7 @@ class geom_path(geom):
}

def handle_na(self, data: pd.DataFrame) -> pd.DataFrame:
def keep(x: Sequence[float]) -> npt.NDArray[np.bool_]:
def keep(x: Sequence[float]) -> BoolArray:
# first non-missing to last non-missing
first = match([False], x, nomatch=1, start=0)[0]
last = len(x) - match([False], x[::-1], nomatch=1, start=0)[0]
Expand All @@ -90,7 +91,7 @@ def keep(x: Sequence[float]) -> npt.NDArray[np.bool_]:

# return data
n1 = len(data)
data = data[bool_idx]
data = data.loc[bool_idx] # pyright: ignore[reportCallIssue,reportArgumentType]
data.reset_index(drop=True, inplace=True)
n2 = len(data)

Expand Down Expand Up @@ -481,7 +482,7 @@ def _draw_segments(data: pd.DataFrame, ax: Axes, **params: Any):
linestyle = data.loc[indices, "linetype"]

coll = LineCollection(
segments,
segments, # pyright: ignore[reportArgumentType]
edgecolor=edgecolor,
linewidth=linewidth,
linestyle=linestyle,
Expand Down
2 changes: 1 addition & 1 deletion plotnine/guides/guides.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def _lrtb(pos):
if just is None:
just = (0.5, 0.5)
elif just in VALID_JUSTIFICATION_WORDS:
just = ensure_xy_location(just)
just = ensure_xy_location(just) # pyright: ignore[reportArgumentType]
elif isinstance(just, (float, int)):
just = (just, just)
return just[idx]
Expand Down
2 changes: 1 addition & 1 deletion plotnine/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def to_pandas(self) -> pd.DataFrame:
# Arrays (strictly numpy)
AnyArray: TypeAlias = NDArray[Any]
BoolArray: TypeAlias = NDArray[np.bool_]
FloatArray: TypeAlias = NDArray[np.float64]
FloatArray: TypeAlias = NDArray[np.floating]
IntArray: TypeAlias = NDArray[np.int64]
StrArray: TypeAlias = NDArray[np.str_]

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ dev = [
]

typing = [
"pyright==1.1.389",
"pyright==1.1.390",
"ipython",
"pandas-stubs",
]
Expand Down

0 comments on commit 7b9c78c

Please sign in to comment.