diff --git a/narwhals/pandas_like/dataframe.py b/narwhals/pandas_like/dataframe.py index 0c57bd0e5..9a1f357e4 100644 --- a/narwhals/pandas_like/dataframe.py +++ b/narwhals/pandas_like/dataframe.py @@ -21,7 +21,7 @@ from narwhals.dtypes import DType from narwhals.pandas_like.group_by import PandasGroupBy from narwhals.pandas_like.series import PandasSeries - from narwhals.pandas_like.typing import IntoExpr + from narwhals.pandas_like.typing import IntoPandasExpr class PandasDataFrame: @@ -92,8 +92,8 @@ def schema(self) -> dict[str, DType]: # --- reshape --- def select( self, - *exprs: IntoExpr | Iterable[IntoExpr], - **named_exprs: IntoExpr, + *exprs: IntoPandasExpr | Iterable[IntoPandasExpr], + **named_exprs: IntoPandasExpr, ) -> Self: new_series = evaluate_into_exprs(self, *exprs, **named_exprs) df = horizontal_concat( @@ -104,7 +104,7 @@ def select( def filter( self, - *predicates: IntoExpr | Iterable[IntoExpr], + *predicates: IntoPandasExpr | Iterable[IntoPandasExpr], ) -> Self: from narwhals.pandas_like.namespace import Namespace @@ -117,8 +117,8 @@ def filter( def with_columns( self, - *exprs: IntoExpr | Iterable[IntoExpr], - **named_exprs: IntoExpr, + *exprs: IntoPandasExpr | Iterable[IntoPandasExpr], + **named_exprs: IntoPandasExpr, ) -> Self: new_series = evaluate_into_exprs(self, *exprs, **named_exprs) df = self._dataframe.assign( diff --git a/narwhals/pandas_like/group_by.py b/narwhals/pandas_like/group_by.py index ad2a26e11..4adee9f23 100644 --- a/narwhals/pandas_like/group_by.py +++ b/narwhals/pandas_like/group_by.py @@ -19,7 +19,7 @@ if TYPE_CHECKING: from narwhals.pandas_like.dataframe import PandasDataFrame from narwhals.pandas_like.expr import PandasExpr - from narwhals.pandas_like.typing import IntoExpr + from narwhals.pandas_like.typing import IntoPandasExpr class PandasGroupBy: @@ -33,8 +33,8 @@ def __init__( def agg( self, - *aggs: IntoExpr | Iterable[IntoExpr], - **named_aggs: IntoExpr, + *aggs: IntoPandasExpr | Iterable[IntoPandasExpr], + **named_aggs: IntoPandasExpr, ) -> PandasDataFrame: df = self._df._dataframe exprs = parse_into_exprs( diff --git a/narwhals/pandas_like/namespace.py b/narwhals/pandas_like/namespace.py index 5c5312e74..f6975a3bd 100644 --- a/narwhals/pandas_like/namespace.py +++ b/narwhals/pandas_like/namespace.py @@ -16,7 +16,7 @@ from narwhals.utils import flatten_str if TYPE_CHECKING: - from narwhals.pandas_like.typing import IntoExpr + from narwhals.pandas_like.typing import IntoPandasExpr class Namespace: @@ -153,13 +153,19 @@ def len(self) -> PandasExpr: ) # --- horizontal --- - def sum_horizontal(self, *exprs: IntoExpr | Iterable[IntoExpr]) -> PandasExpr: + def sum_horizontal( + self, *exprs: IntoPandasExpr | Iterable[IntoPandasExpr] + ) -> PandasExpr: return reduce(lambda x, y: x + y, parse_into_exprs(self._implementation, *exprs)) - def all_horizontal(self, *exprs: IntoExpr | Iterable[IntoExpr]) -> PandasExpr: + def all_horizontal( + self, *exprs: IntoPandasExpr | Iterable[IntoPandasExpr] + ) -> PandasExpr: return reduce(lambda x, y: x & y, parse_into_exprs(self._implementation, *exprs)) - def any_horizontal(self, *exprs: IntoExpr | Iterable[IntoExpr]) -> PandasExpr: + def any_horizontal( + self, *exprs: IntoPandasExpr | Iterable[IntoPandasExpr] + ) -> PandasExpr: return reduce(lambda x, y: x | y, parse_into_exprs(self._implementation, *exprs)) def concat( diff --git a/narwhals/pandas_like/typing.py b/narwhals/pandas_like/typing.py index ca1fd0f37..89b0051b4 100644 --- a/narwhals/pandas_like/typing.py +++ b/narwhals/pandas_like/typing.py @@ -7,4 +7,4 @@ from narwhals.pandas_like.expr import PandasExpr from narwhals.pandas_like.series import PandasSeries - IntoExpr: TypeAlias = PandasExpr | str | int | float | PandasSeries + IntoPandasExpr: TypeAlias = PandasExpr | str | int | float | PandasSeries diff --git a/narwhals/pandas_like/utils.py b/narwhals/pandas_like/utils.py index 89b5aefbb..295090a24 100644 --- a/narwhals/pandas_like/utils.py +++ b/narwhals/pandas_like/utils.py @@ -19,7 +19,7 @@ ExprT = TypeVar("ExprT", bound=PandasExpr) - from narwhals.pandas_like.typing import IntoExpr + from narwhals.pandas_like.typing import IntoPandasExpr def validate_column_comparand(other: Any) -> Any: @@ -85,7 +85,9 @@ def maybe_evaluate_expr(df: PandasDataFrame, arg: Any) -> Any: def parse_into_exprs( - implementation: str, *exprs: IntoExpr | Iterable[IntoExpr], **named_exprs: IntoExpr + implementation: str, + *exprs: IntoPandasExpr | Iterable[IntoPandasExpr], + **named_exprs: IntoPandasExpr, ) -> list[PandasExpr]: out = [parse_into_expr(implementation, into_expr) for into_expr in flatten(*exprs)] # type: ignore[arg-type] for name, expr in named_exprs.items(): @@ -93,7 +95,7 @@ def parse_into_exprs( return out -def parse_into_expr(implementation: str, into_expr: IntoExpr) -> PandasExpr: +def parse_into_expr(implementation: str, into_expr: IntoPandasExpr) -> PandasExpr: from narwhals.expression import Expr from narwhals.pandas_like.namespace import Namespace @@ -107,7 +109,9 @@ def parse_into_expr(implementation: str, into_expr: IntoExpr) -> PandasExpr: raise TypeError(msg) -def evaluate_into_expr(df: PandasDataFrame, into_expr: IntoExpr) -> list[PandasSeries]: +def evaluate_into_expr( + df: PandasDataFrame, into_expr: IntoPandasExpr +) -> list[PandasSeries]: """ Return list of raw columns. """ @@ -117,8 +121,8 @@ def evaluate_into_expr(df: PandasDataFrame, into_expr: IntoExpr) -> list[PandasS def evaluate_into_exprs( df: PandasDataFrame, - *exprs: IntoExpr | Iterable[IntoExpr], - **named_exprs: IntoExpr, + *exprs: IntoPandasExpr | Iterable[IntoPandasExpr], + **named_exprs: IntoPandasExpr, ) -> list[PandasSeries]: """Evaluate each expr into Series.""" series: list[PandasSeries] = [