Skip to content

Commit bc93782

Browse files
committed
chore(typing): fix variance issues
1 parent 6cb725c commit bc93782

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

narwhals/_compliant/dataframe.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from narwhals._compliant.typing import CompliantSeriesT_co
1212
from narwhals._compliant.typing import EagerSeriesT
13+
from narwhals._compliant.typing import EagerSeriesT_co
1314

1415
if TYPE_CHECKING:
1516
from typing_extensions import Self
@@ -58,12 +59,12 @@ def schema(self) -> Mapping[str, DType]: ...
5859
def _iter_columns(self) -> Iterator[Any]: ...
5960

6061

61-
class EagerDataFrame(CompliantDataFrame[EagerSeriesT], Protocol[EagerSeriesT]): # pyright: ignore[reportInvalidTypeVarUse]
62+
class EagerDataFrame(CompliantDataFrame[EagerSeriesT_co], Protocol[EagerSeriesT_co]):
6263
def _maybe_evaluate_expr(
63-
self, expr: EagerExpr[EagerDataFrame[EagerSeriesT], EagerSeriesT] | T, /
64-
) -> EagerSeriesT | T:
64+
self, expr: EagerExpr[EagerDataFrame[EagerSeriesT_co], EagerSeriesT_co] | T, /
65+
) -> EagerSeriesT_co | T:
6566
if is_eager_expr(expr):
66-
result: Sequence[EagerSeriesT] = expr(self)
67+
result: Sequence[EagerSeriesT_co] = expr(self)
6768
if len(result) > 1:
6869
msg = (
6970
"Multi-output expressions (e.g. `nw.all()` or `nw.col('a', 'b')`) "

narwhals/_compliant/series.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ def alias(self, name: str) -> Self: ...
3030

3131

3232
class EagerSeries(CompliantSeries, Protocol[NativeSeriesT_co]):
33-
_native_series: NativeSeriesT_co
33+
_native_series: Any
3434
_implementation: Implementation
3535
_backend_version: tuple[int, ...]
3636
_version: Version
3737

38+
@property
39+
def native(self) -> NativeSeriesT_co: ...
40+
3841
def _from_scalar(self, value: Any) -> Self:
3942
return self._from_iterable([value], name=self.name, context=self)
4043

narwhals/_compliant/typing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@
4040

4141
EagerDataFrameT = TypeVar("EagerDataFrameT", bound="EagerDataFrame[Any]")
4242
EagerSeriesT = TypeVar("EagerSeriesT", bound="EagerSeries[Any]")
43+
EagerSeriesT_co = TypeVar("EagerSeriesT_co", bound="EagerSeries[Any]", covariant=True)

0 commit comments

Comments
 (0)