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
10 changes: 5 additions & 5 deletions narwhals/_compliant/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
LazyExprT,
NativeExprT,
)
from narwhals._typing_compat import Protocol38, deprecated
from narwhals._typing_compat import deprecated
from narwhals._utils import _StoresCompliant
from narwhals.dependencies import get_numpy, is_numpy_array

Expand Down Expand Up @@ -66,7 +66,7 @@ def between(self, *args: Any, **kwds: Any) -> Any: ...
def isin(self, *args: Any, **kwds: Any) -> Any: ...


class CompliantExpr(Protocol38[CompliantFrameT, CompliantSeriesOrNativeExprT_co]):
class CompliantExpr(Protocol[CompliantFrameT, CompliantSeriesOrNativeExprT_co]):
_implementation: Implementation
_version: Version
_evaluate_output_names: EvalNames[CompliantFrameT]
Expand Down Expand Up @@ -264,7 +264,7 @@ def struct(self) -> StructNamespace[Self]: ...

class DepthTrackingExpr(
CompliantExpr[CompliantFrameT, CompliantSeriesOrNativeExprT_co],
Protocol38[CompliantFrameT, CompliantSeriesOrNativeExprT_co],
Protocol[CompliantFrameT, CompliantSeriesOrNativeExprT_co],
):
_depth: int
_function_name: str
Expand Down Expand Up @@ -302,7 +302,7 @@ def __repr__(self) -> str: # pragma: no cover

class EagerExpr(
DepthTrackingExpr[EagerDataFrameT, EagerSeriesT],
Protocol38[EagerDataFrameT, EagerSeriesT],
Protocol[EagerDataFrameT, EagerSeriesT],
):
_call: EvalSeries[EagerDataFrameT, EagerSeriesT]
_scalar_kwargs: ScalarKwargs
Expand Down Expand Up @@ -899,7 +899,7 @@ def struct(self) -> EagerExprStructNamespace[Self]:
# mypy thinks `NativeExprT` should be covariant, pyright thinks it should be invariant
class LazyExpr( # type: ignore[misc]
CompliantExpr[CompliantLazyFrameT, NativeExprT],
Protocol38[CompliantLazyFrameT, NativeExprT],
Protocol[CompliantLazyFrameT, NativeExprT],
):
def _with_alias_output_names(self, func: AliasNames | None, /) -> Self: ...
def alias(self, name: str) -> Self:
Expand Down
13 changes: 6 additions & 7 deletions narwhals/_compliant/group_by.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import re
from typing import TYPE_CHECKING, Any, Callable, ClassVar, TypeVar
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Protocol, TypeVar

from narwhals._compliant.typing import (
CompliantDataFrameAny,
Expand All @@ -14,7 +14,6 @@
EagerExprT_contra,
NarwhalsAggregation,
)
from narwhals._typing_compat import Protocol38
from narwhals._utils import is_sequence_of

if TYPE_CHECKING:
Expand All @@ -33,7 +32,7 @@
_RE_LEAF_NAME: re.Pattern[str] = re.compile(r"(\w+->)")


class CompliantGroupBy(Protocol38[CompliantFrameT_co, CompliantExprT_contra]):
class CompliantGroupBy(Protocol[CompliantFrameT_co, CompliantExprT_contra]):
_compliant_frame: Any

@property
Expand All @@ -54,14 +53,14 @@ def agg(self, *exprs: CompliantExprT_contra) -> CompliantFrameT_co: ...

class DataFrameGroupBy(
CompliantGroupBy[CompliantDataFrameT_co, CompliantExprT_contra],
Protocol38[CompliantDataFrameT_co, CompliantExprT_contra],
Protocol[CompliantDataFrameT_co, CompliantExprT_contra],
):
def __iter__(self) -> Iterator[tuple[Any, CompliantDataFrameT_co]]: ...


class ParseKeysGroupBy(
CompliantGroupBy[CompliantFrameT_co, CompliantExprT_contra],
Protocol38[CompliantFrameT_co, CompliantExprT_contra],
Protocol[CompliantFrameT_co, CompliantExprT_contra],
):
def _parse_keys(
self,
Expand Down Expand Up @@ -118,7 +117,7 @@ def _temporary_name(key: str) -> str:

class DepthTrackingGroupBy(
ParseKeysGroupBy[CompliantFrameT_co, DepthTrackingExprT_contra],
Protocol38[CompliantFrameT_co, DepthTrackingExprT_contra, NativeAggregationT_co],
Protocol[CompliantFrameT_co, DepthTrackingExprT_contra, NativeAggregationT_co],
):
"""`CompliantGroupBy` variant, deals with `Eager` and other backends that utilize `CompliantExpr._depth`."""

Expand Down Expand Up @@ -175,5 +174,5 @@ class EagerGroupBy(
CompliantDataFrameT_co, EagerExprT_contra, NativeAggregationT_co
],
DataFrameGroupBy[CompliantDataFrameT_co, EagerExprT_contra],
Protocol38[CompliantDataFrameT_co, EagerExprT_contra, NativeAggregationT_co],
Protocol[CompliantDataFrameT_co, EagerExprT_contra, NativeAggregationT_co],
): ...
3 changes: 1 addition & 2 deletions narwhals/_compliant/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import TYPE_CHECKING, Protocol, TypeVar, overload

from narwhals._compliant.expr import CompliantExpr
from narwhals._typing_compat import Protocol38
from narwhals._utils import (
_parse_time_unit_and_time_zone,
dtype_matches_time_unit_and_time_zone,
Expand Down Expand Up @@ -197,7 +196,7 @@ def _iter_columns_dtypes(self, df: LazyFrameT, /) -> Iterator[tuple[ExprT, DType


class CompliantSelector(
CompliantExpr[FrameT, SeriesOrExprT], Protocol38[FrameT, SeriesOrExprT]
CompliantExpr[FrameT, SeriesOrExprT], Protocol[FrameT, SeriesOrExprT]
):
_call: EvalSeries[FrameT, SeriesOrExprT]
_function_name: str
Expand Down
9 changes: 4 additions & 5 deletions narwhals/_compliant/when_then.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, TypeVar, cast
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, cast

from narwhals._compliant.expr import CompliantExpr
from narwhals._compliant.typing import (
Expand All @@ -13,7 +13,6 @@
LazyExprAny,
NativeSeriesT,
)
from narwhals._typing_compat import Protocol38

if TYPE_CHECKING:
from collections.abc import Sequence
Expand All @@ -39,7 +38,7 @@
"""Anything that is convertible into a `CompliantExpr`."""


class CompliantWhen(Protocol38[FrameT, SeriesT, ExprT]):
class CompliantWhen(Protocol[FrameT, SeriesT, ExprT]):
_condition: ExprT
_then_value: IntoExpr[SeriesT, ExprT]
_otherwise_value: IntoExpr[SeriesT, ExprT] | None
Expand Down Expand Up @@ -71,7 +70,7 @@ def from_expr(cls, condition: ExprT, /, *, context: _LimitedContext) -> Self:


class CompliantThen(
CompliantExpr[FrameT, SeriesT], Protocol38[FrameT, SeriesT, ExprT, WhenT_contra]
CompliantExpr[FrameT, SeriesT], Protocol[FrameT, SeriesT, ExprT, WhenT_contra]
):
_call: EvalSeries[FrameT, SeriesT]
_when_value: CompliantWhen[FrameT, SeriesT, ExprT]
Expand Down Expand Up @@ -99,7 +98,7 @@ def otherwise(self, otherwise: IntoExpr[SeriesT, ExprT], /) -> ExprT:

class EagerWhen(
CompliantWhen[EagerDataFrameT, EagerSeriesT, EagerExprT],
Protocol38[EagerDataFrameT, EagerSeriesT, EagerExprT, NativeSeriesT],
Protocol[EagerDataFrameT, EagerSeriesT, EagerExprT, NativeSeriesT],
):
def _if_then_else(
self,
Expand Down
7 changes: 2 additions & 5 deletions narwhals/_sql/expr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Callable, Literal, cast
from typing import TYPE_CHECKING, Any, Callable, Literal, Protocol, cast

from narwhals._compliant.expr import LazyExpr
from narwhals._compliant.typing import (
Expand All @@ -16,7 +16,6 @@
combine_evaluate_output_names,
)
from narwhals._sql.typing import SQLLazyFrameT
from narwhals._typing_compat import Protocol38
from narwhals._utils import Implementation, Version, not_implemented

if TYPE_CHECKING:
Expand All @@ -29,9 +28,7 @@
from narwhals.typing import PythonLiteral, RankMethod


class SQLExpr(
LazyExpr[SQLLazyFrameT, NativeExprT], Protocol38[SQLLazyFrameT, NativeExprT]
):
class SQLExpr(LazyExpr[SQLLazyFrameT, NativeExprT], Protocol[SQLLazyFrameT, NativeExprT]):
_call: EvalSeries[SQLLazyFrameT, NativeExprT]
_evaluate_output_names: EvalNames[SQLLazyFrameT]
_alias_output_names: AliasNames | None
Expand Down
5 changes: 2 additions & 3 deletions narwhals/_sql/group_by.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Protocol

from narwhals._compliant.group_by import CompliantGroupBy, ParseKeysGroupBy
from narwhals._compliant.typing import CompliantLazyFrameT_co, NativeExprT_co
from narwhals._sql.typing import SQLExprT_contra
from narwhals._typing_compat import Protocol38

if TYPE_CHECKING:
from collections.abc import Iterable, Iterator
Expand All @@ -14,7 +13,7 @@
class SQLGroupBy(
ParseKeysGroupBy[CompliantLazyFrameT_co, SQLExprT_contra],
CompliantGroupBy[CompliantLazyFrameT_co, SQLExprT_contra],
Protocol38[CompliantLazyFrameT_co, SQLExprT_contra, NativeExprT_co],
Protocol[CompliantLazyFrameT_co, SQLExprT_contra, NativeExprT_co],
):
_keys: list[str]
_output_key_names: list[str]
Expand Down
7 changes: 3 additions & 4 deletions narwhals/_sql/when_then.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Callable
from typing import TYPE_CHECKING, Callable, Protocol

from narwhals._compliant.typing import CompliantLazyFrameT, NativeExprT
from narwhals._compliant.when_then import CompliantThen, CompliantWhen
from narwhals._sql.typing import SQLExprT
from narwhals._typing_compat import Protocol38

if TYPE_CHECKING:
from collections.abc import Sequence
Expand All @@ -20,7 +19,7 @@

class SQLWhen(
CompliantWhen[CompliantLazyFrameT, NativeExprT, SQLExprT],
Protocol38[CompliantLazyFrameT, NativeExprT, SQLExprT],
Protocol[CompliantLazyFrameT, NativeExprT, SQLExprT],
):
when: Callable[..., NativeExprT]
lit: Callable[..., NativeExprT]
Expand Down Expand Up @@ -82,7 +81,7 @@ class SQLThen(
SQLExprT,
SQLWhen[CompliantLazyFrameT, NativeExprT, SQLExprT],
],
Protocol38[CompliantLazyFrameT, NativeExprT, SQLExprT],
Protocol[CompliantLazyFrameT, NativeExprT, SQLExprT],
):
_window_function: WindowFunction[CompliantLazyFrameT, NativeExprT] | None

Expand Down
11 changes: 2 additions & 9 deletions narwhals/_typing_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
Import from here to avoid introducing a runtime dependency on [`typing_extensions`]

## Notes
- `Protocol38`
- https://github.com/narwhals-dev/narwhals/pull/2064#discussion_r1965921386
- https://github.com/narwhals-dev/narwhals/pull/2294#discussion_r2014534830
- `TypeVar` defaults
- https://typing.python.org/en/latest/spec/generics.html#type-parameter-defaults
- https://peps.python.org/pep-0696/
Expand All @@ -25,7 +22,7 @@
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
from typing import Callable, Protocol as Protocol38
from typing import Callable

if sys.version_info >= (3, 13):
from typing import TypeVar
Expand Down Expand Up @@ -85,9 +82,5 @@ def assert_never(arg: Never, /) -> Never:
)
raise AssertionError(msg)

# TODO @dangotbanned: Remove after dropping `3.8` (#2084)
# - https://github.com/narwhals-dev/narwhals/pull/2064#discussion_r1965921386
from typing import Protocol as Protocol38


__all__ = ["Protocol38", "TypeVar", "assert_never", "deprecated"]
__all__ = ["TypeVar", "assert_never", "deprecated"]
Loading