Skip to content

Commit 998993a

Browse files
committed
wip unbroken
1 parent 6db674a commit 998993a

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

narwhals/pandas_like/dataframe.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from narwhals.pandas_like.utils import horizontal_concat
1212
from narwhals.pandas_like.utils import validate_dataframe_comparand
1313
from narwhals.spec import DataFrame as DataFrameT
14-
from narwhals.spec import IntoExpr
1514
from narwhals.spec import LazyFrame as LazyFrameProtocol
1615
from narwhals.spec import Namespace as NamespaceProtocol
1716

@@ -23,6 +22,7 @@
2322
from narwhals.pandas_like.group_by_object import GroupBy
2423
from narwhals.pandas_like.group_by_object import LazyGroupBy
2524
from narwhals.pandas_like.namespace import Namespace
25+
from narwhals.pandas_like.utils import IntoExpr
2626

2727

2828
class DataFrame(DataFrameT):

narwhals/pandas_like/expr.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
from typing import Any
55
from typing import Callable
66

7-
from narwhals.pandas_like.series import Series
87
from narwhals.pandas_like.utils import register_expression_call
9-
from narwhals.spec import DataFrame as DataFrameT
108
from narwhals.spec import Expr as ExprT
119
from narwhals.spec import ExprStringNamespace as ExprStringNamespaceT
12-
from narwhals.spec import LazyFrame as LazyFrameProtocol
1310
from narwhals.spec import Namespace as NamespaceProtocol
14-
from narwhals.spec import Series as SeriesProtocol
1511

1612
if TYPE_CHECKING:
1713
from typing_extensions import Self
1814

15+
from narwhals.pandas_like.dataframe import DataFrame
16+
from narwhals.pandas_like.dataframe import LazyFrame
17+
from narwhals.pandas_like.series import Series
18+
1919

2020
class Expr(ExprT):
2121
def __init__( # noqa: PLR0913
2222
self,
23-
call: Callable[[DataFrameT | LazyFrameProtocol], list[SeriesProtocol]],
23+
call: Callable[[DataFrame | LazyFrame], list[Series]],
2424
*,
2525
depth: int | None,
2626
function_name: str | None,
@@ -50,6 +50,8 @@ def __repr__(self) -> str:
5050
def from_column_names(
5151
cls: type[Self], *column_names: str, implementation: str
5252
) -> Self:
53+
from narwhals.pandas_like.series import Series
54+
5355
return cls(
5456
lambda df: [
5557
Series(
@@ -197,7 +199,7 @@ def alias(self, name: str) -> Self:
197199
if self._depth is None:
198200
msg = "Unreachable code, please report a bug"
199201
raise AssertionError(msg)
200-
return Expr(
202+
return self.__class__(
201203
lambda df: [series.alias(name) for series in self.call(df)],
202204
depth=self._depth,
203205
function_name=self._function_name,
@@ -217,6 +219,8 @@ def __init__(self, expr: ExprT) -> None:
217219

218220
def ends_with(self, suffix: str) -> Expr:
219221
# TODO make a register_expression_call for namespaces
222+
from narwhals.pandas_like.series import Series
223+
220224
return Expr(
221225
lambda df: [
222226
Series(
@@ -234,6 +238,8 @@ def ends_with(self, suffix: str) -> Expr:
234238
)
235239

236240
def strip_chars(self, characters: str = " ") -> Expr:
241+
from narwhals.pandas_like.series import Series
242+
237243
return Expr(
238244
lambda df: [
239245
Series(

narwhals/pandas_like/namespace.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414
from narwhals.pandas_like.utils import parse_into_exprs
1515
from narwhals.pandas_like.utils import series_from_iterable
1616
from narwhals.spec import AnyDataFrame
17-
from narwhals.spec import DataFrame as DataFrameT
1817
from narwhals.spec import IntoExpr
19-
from narwhals.spec import LazyFrame as LazyFrameProtocol
2018
from narwhals.spec import Namespace as NamespaceProtocol
21-
from narwhals.spec import Series as SeriesProtocol
2219

2320

2421
class Namespace(NamespaceProtocol):
@@ -109,7 +106,7 @@ def len(self) -> Expr:
109106

110107
def _create_expr_from_callable( # noqa: PLR0913
111108
self,
112-
func: Callable[[DataFrameT | LazyFrameProtocol], list[SeriesProtocol]],
109+
func: Callable[[DataFrame | LazyFrame], list[Series]],
113110
*,
114111
depth: int,
115112
function_name: str | None,
@@ -125,9 +122,7 @@ def _create_expr_from_callable( # noqa: PLR0913
125122
implementation=self._implementation,
126123
)
127124

128-
def _create_series_from_scalar(
129-
self, value: Any, series: SeriesProtocol
130-
) -> SeriesProtocol:
125+
def _create_series_from_scalar(self, value: Any, series: Series) -> Series:
131126
return Series(
132127
series_from_iterable(
133128
[value],
@@ -139,7 +134,7 @@ def _create_series_from_scalar(
139134
implementation=self._implementation,
140135
)
141136

142-
def _create_expr_from_series(self, series: SeriesProtocol) -> Expr:
137+
def _create_expr_from_series(self, series: Series) -> Expr:
143138
return Expr(
144139
lambda _df: [series],
145140
depth=0,

narwhals/pandas_like/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def __repr__(self) -> str: # pragma: no cover
4949
+ "┘\n"
5050
)
5151

52-
def _from_series(self, series: Any) -> Series:
53-
return Series(
52+
def _from_series(self, series: Any) -> Self:
53+
return self.__class__(
5454
series.rename(series.name, copy=False),
5555
api_version=self.api_version,
5656
implementation=self._implementation,

0 commit comments

Comments
 (0)