Skip to content

Commit

Permalink
make it generic
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Mar 16, 2024
1 parent 3043ef9 commit a1620e1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions f.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# ruff: noqa
# type: ignore
from typing import Any
from typing import Any, TYPE_CHECKING, TypeVar
import pandas as pd
import polars as pl

import narwhals as nw

T = TypeVar("T")


def my_agnostic_function(
suppliers_native: nw.typing.T,
parts_native: nw.typing.T,
) -> nw.typing.T:
suppliers_native: T,
parts_native: T,
) -> T:
suppliers = nw.DataFrame(suppliers_native)
parts = nw.DataFrame(parts_native)

Expand Down
4 changes: 2 additions & 2 deletions narwhals/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class DataFrame(Generic[T]):
def __init__(
self,
df: Any,
df: T,
*,
is_eager: bool = False,
is_lazy: bool = False,
Expand All @@ -35,7 +35,7 @@ def __init__(
self._is_eager = is_eager
self._is_lazy = is_lazy
if implementation is not None:
self._dataframe = df
self._dataframe: Any = df
self._implementation = implementation
return
if (pl := get_polars()) is not None and isinstance(
Expand Down
4 changes: 2 additions & 2 deletions narwhals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
class Series(Generic[T]):
def __init__(
self,
series: Any,
series: T,
*,
implementation: str | None = None,
) -> None:
from narwhals.pandas_like.series import PandasSeries

if implementation is not None:
self._series = series
self._series: Any = series
self._implementation = implementation
return
if (pl := get_polars()) is not None and isinstance(series, pl.Series):
Expand Down

0 comments on commit a1620e1

Please sign in to comment.