Skip to content

chore(typing): Widen _utils signatures #2712

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 narwhals/_pandas_like/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ def select_columns_by_name(
# See https://github.com/narwhals-dev/narwhals/issues/1349#issuecomment-2470118122
# for why we need this
if error := check_columns_exist(
column_names, # type: ignore[arg-type]
column_names,
available=df.columns.tolist(), # type: ignore[attr-defined]
):
raise error
Expand All @@ -581,7 +581,7 @@ def select_columns_by_name(
return df[column_names] # type: ignore[index]
except KeyError as e:
if error := check_columns_exist(
column_names, # type: ignore[arg-type]
column_names,
available=df.columns.tolist(), # type: ignore[attr-defined]
):
raise error from e
Expand Down
12 changes: 6 additions & 6 deletions narwhals/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os
import re
from collections.abc import Container, Iterable, Iterator, Mapping, Sequence
from collections.abc import Collection, Container, Iterable, Iterator, Mapping, Sequence
from datetime import timezone
from enum import Enum, auto
from functools import lru_cache, wraps
Expand Down Expand Up @@ -1181,7 +1181,7 @@ def is_ordered_categorical(series: Series[Any]) -> bool:


def generate_unique_token(
n_bytes: int, columns: Sequence[str]
n_bytes: int, columns: Container[str]
) -> str: # pragma: no cover
msg = (
"Use `generate_temporary_column_name` instead. `generate_unique_token` is "
Expand All @@ -1191,7 +1191,7 @@ def generate_unique_token(
return generate_temporary_column_name(n_bytes=n_bytes, columns=columns)


def generate_temporary_column_name(n_bytes: int, columns: Sequence[str]) -> str:
def generate_temporary_column_name(n_bytes: int, columns: Container[str]) -> str:
"""Generates a unique column name that is not present in the given list of columns.

It relies on [python secrets token_hex](https://docs.python.org/3/library/secrets.html#secrets.token_hex)
Expand Down Expand Up @@ -1489,7 +1489,7 @@ def generate_repr(header: str, native_repr: str) -> str:


def check_columns_exist(
subset: Sequence[str], /, *, available: Sequence[str]
subset: Collection[str], /, *, available: Collection[str]
) -> ColumnNotFoundError | None:
if missing := set(subset).difference(available):
return ColumnNotFoundError.from_missing_and_available_column_names(
Expand All @@ -1498,7 +1498,7 @@ def check_columns_exist(
return None


def check_column_names_are_unique(columns: Sequence[str]) -> None:
def check_column_names_are_unique(columns: Collection[str]) -> None:
len_unique_columns = len(set(columns))
if len(columns) != len_unique_columns:
from collections import Counter
Expand Down Expand Up @@ -1622,7 +1622,7 @@ def supports_arrow_c_stream(obj: Any) -> TypeIs[ArrowStreamExportable]:


def _remap_full_join_keys(
left_on: Sequence[str], right_on: Sequence[str], suffix: str
left_on: Collection[str], right_on: Collection[str], suffix: str
) -> dict[str, str]:
"""Remap join keys to avoid collisions.

Expand Down
4 changes: 2 additions & 2 deletions narwhals/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Iterable, Sequence
from collections.abc import Collection, Iterable


class NarwhalsError(ValueError):
Expand Down Expand Up @@ -35,7 +35,7 @@ def __init__(self, message: str) -> None:

@classmethod
def from_missing_and_available_column_names(
cls, missing_columns: Iterable[str], available_columns: Sequence[str], /
cls, missing_columns: Iterable[str], available_columns: Collection[str], /
) -> ColumnNotFoundError:
message = (
f"The following columns were not found: {sorted(missing_columns)}"
Expand Down
Loading