Skip to content
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
126 changes: 52 additions & 74 deletions pixi.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions skops/card/_markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
from collections.abc import Mapping
from contextlib import contextmanager
from typing import Any, Sequence
from typing import Any

from skops.card._model_card import TableSection

Expand Down Expand Up @@ -258,13 +258,13 @@ def _table(self, item) -> str:
# pandoc < 2.5
columns, body = self._table_old(item)

table: Mapping[str, Sequence[Any]]
table: Mapping[str, list[Any]]
if not body:
table = {key: [] for key in columns}
else:
# body is row oriented, transpose to column oriented
data_transposed = zip(*body)
table = {key: val for key, val in zip(columns, data_transposed)}
table = {key: list(val) for key, val in zip(columns, data_transposed)}

res = TableSection(title="", content="", table=table).format()
return res
Expand Down
14 changes: 7 additions & 7 deletions skops/card/_model_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from hashlib import sha256
from pathlib import Path
from reprlib import Repr
from typing import Any, Iterator, List, Literal, Optional, Sequence
from typing import Any, Iterator, Literal

import joblib
from prettytable import PrettyTable, TableStyle
Expand Down Expand Up @@ -178,7 +178,7 @@ def __repr__(self) -> str:
class TableSection(Section):
"""Adds a table to the model card"""

table: Mapping[str, Sequence[Any]] = field(default_factory=dict)
table: Mapping[str, list[Any]] = field(default_factory=dict)
folded: bool = False

def __post_init__(self) -> None:
Expand Down Expand Up @@ -228,7 +228,7 @@ def __repr__(self) -> str:


def _load_model(
model: Any, trusted: Optional[Sequence[str]] = None, allow_pickle: bool = False
model: Any, trusted: list[str] | None = None, allow_pickle: bool = False
) -> Any:
"""Return a model instance.

Expand Down Expand Up @@ -403,7 +403,7 @@ def __init__(
model_format: Literal["pickle", "skops"] | None = None,
model_diagram: bool | Literal["auto"] | str = "auto",
template: Literal["skops"] | dict[str, str] | None = "skops",
trusted: Optional[List[str]] = None,
trusted: list[str] | None = None,
allow_pickle: bool = False,
) -> None:
self.model = model
Expand Down Expand Up @@ -535,7 +535,7 @@ def add(self, folded: bool = False, **kwargs: str) -> Self:
return self

def _select(
self, subsection_names: Sequence[str], create: bool = True
self, subsection_names: list[str], create: bool = True
) -> dict[str, Section]:
"""Select a single section from the data.

Expand Down Expand Up @@ -629,7 +629,7 @@ def select(self, key: str) -> Section:
parent_section = self._select(subsection_names, create=False)
return parent_section[leaf_node_name]

def delete(self, key: str | Sequence[str]) -> None:
def delete(self, key: str | list[str]) -> None:
"""Delete a section from the model card.

To delete a subsection of an existing section, use a ``"/"`` in the
Expand Down Expand Up @@ -1002,7 +1002,7 @@ def add_metrics(
def add_permutation_importances(
self,
permutation_importances,
columns: Sequence[str],
columns: list[str],
plot_file: str | Path = "permutation_importances.png",
plot_name: str = "Permutation Importances",
overwrite: bool = False,
Expand Down
3 changes: 1 addition & 2 deletions skops/cli/_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import pathlib
import pickle
from typing import Optional

from skops.cli._utils import get_log_level
from skops.io import dumps, get_untrusted_types
Expand Down Expand Up @@ -59,7 +58,7 @@ def _convert_file(


def format_parser(
parser: Optional[argparse.ArgumentParser] = None,
parser: argparse.ArgumentParser | None = None,
) -> argparse.ArgumentParser:
"""Adds arguments and help to parent CLI parser for the convert method."""

Expand Down
18 changes: 9 additions & 9 deletions skops/io/_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import io
from contextlib import contextmanager
from typing import Any, Dict, Generator, Iterable, List, Optional, Sequence, Type, Union
from typing import Any, Generator, Iterable, Sequence, Type, Union

from ._protocol import PROTOCOL
from ._utils import LoadContext, get_module, get_type_paths
from .exceptions import UntrustedTypesFoundException

NODE_TYPE_MAPPING: dict[tuple[str, int], Type[Node]] = {}
VALID_NODE_CHILD_TYPES = Optional[
Union["Node", List["Node"], Dict[str, "Node"], Type, str, io.BytesIO]
VALID_NODE_CHILD_TYPES = Union[
"Node", list["Node"], dict[str, "Node"], Type, str, io.BytesIO, None
]


def check_type(module_name: str, type_name: str, trusted: Sequence[str]) -> bool:
def check_type(module_name: str, type_name: str, trusted: list[str]) -> bool:
"""Check if a type is safe to load.
A type is safe to load only if it's present in the trusted list.
Expand Down Expand Up @@ -135,7 +135,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: Sequence[str] | None = None,
memoize: bool = True,
) -> None:
self.class_name, self.module_name = state["__class__"], state["__module__"]
Expand Down Expand Up @@ -173,8 +173,8 @@ def _construct(self):

@staticmethod
def _get_trusted(
trusted: Optional[Sequence[Union[str, Type]]],
default: Sequence[Union[str, Type]],
trusted: Sequence[str] | None,
default: Sequence[str | type[Any]],
) -> list[str]:
"""Return a trusted list, or True.
Expand Down Expand Up @@ -279,7 +279,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[List[str]] = None,
trusted: Sequence[str] | None = None,
):
# we pass memoize as False because we don't want to memoize the cached
# node.
Expand All @@ -303,7 +303,7 @@ def _construct(self):
def get_tree(
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]],
trusted: Sequence[str] | None,
) -> Node:
"""Get the tree of nodes.
Expand Down
34 changes: 17 additions & 17 deletions skops/io/_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from functools import partial
from reprlib import Repr
from types import FunctionType, MethodType
from typing import Any, Optional, Sequence
from typing import Any

import numpy as np

Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.trusted = self._get_trusted(trusted, [dict, "collections.OrderedDict"])
Expand Down Expand Up @@ -102,7 +102,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.trusted = ["collections.defaultdict"]
Expand Down Expand Up @@ -138,7 +138,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.trusted = self._get_trusted(trusted, [list])
Expand Down Expand Up @@ -170,7 +170,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.trusted = self._get_trusted(trusted, [set])
Expand Down Expand Up @@ -202,7 +202,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.trusted = self._get_trusted(trusted, [tuple])
Expand Down Expand Up @@ -249,7 +249,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
# TODO: what do we trust?
Expand Down Expand Up @@ -293,7 +293,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
# TODO: should we trust anything?
Expand Down Expand Up @@ -334,7 +334,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
# TODO: what do we trust?
Expand Down Expand Up @@ -369,7 +369,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.trusted = self._get_trusted(trusted, [slice])
Expand Down Expand Up @@ -449,7 +449,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.children = {
Expand All @@ -467,7 +467,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)

Expand Down Expand Up @@ -528,7 +528,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
obj = get_tree(state["content"]["obj"], load_context, trusted=trusted)
Expand Down Expand Up @@ -572,7 +572,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.content = state["content"]
Expand Down Expand Up @@ -625,7 +625,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.trusted = self._get_trusted(trusted, [bytes])
Expand All @@ -646,7 +646,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.trusted = self._get_trusted(trusted, [bytearray])
Expand Down Expand Up @@ -676,7 +676,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
if self.module_name != "operator":
Expand Down
12 changes: 6 additions & 6 deletions skops/io/_numpy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import io
from typing import Any, Optional, Sequence
from typing import Any

import numpy as np

Expand Down Expand Up @@ -61,7 +61,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.type = state["type"]
Expand Down Expand Up @@ -128,7 +128,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.trusted = self._get_trusted(trusted, [np.ma.MaskedArray])
Expand Down Expand Up @@ -159,7 +159,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
# TODO
Expand Down Expand Up @@ -191,7 +191,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.children = {
Expand Down Expand Up @@ -242,7 +242,7 @@ def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
trusted: list[str] | None = None,
) -> None:
super().__init__(state, load_context, trusted)
self.children = {
Expand Down
Loading