Skip to content

Commit f87a629

Browse files
committed
refactor: migrate to ArrowExpr._reuse_series_namespace_implementation
Only 3 errors left - all seem to be `Expr.is_in`
1 parent afddd4c commit f87a629

File tree

4 files changed

+60
-70
lines changed

4 files changed

+60
-70
lines changed

narwhals/_arrow/expr_cat.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from typing import TYPE_CHECKING
44

5-
from narwhals._expression_parsing import reuse_series_namespace_implementation
6-
75
if TYPE_CHECKING:
86
from typing_extensions import Self
97

@@ -15,6 +13,6 @@ def __init__(self: Self, expr: ArrowExpr) -> None:
1513
self._compliant_expr = expr
1614

1715
def get_categories(self: Self) -> ArrowExpr:
18-
return reuse_series_namespace_implementation(
19-
self._compliant_expr, "cat", "get_categories"
16+
return self._compliant_expr._reuse_series_namespace_implementation(
17+
"cat", "get_categories"
2018
)

narwhals/_arrow/expr_dt.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from typing import TYPE_CHECKING
44

5-
from narwhals._expression_parsing import reuse_series_namespace_implementation
6-
75
if TYPE_CHECKING:
86
from typing_extensions import Self
97

@@ -16,92 +14,92 @@ def __init__(self: Self, expr: ArrowExpr) -> None:
1614
self._compliant_expr = expr
1715

1816
def to_string(self: Self, format: str) -> ArrowExpr: # noqa: A002
19-
return reuse_series_namespace_implementation(
20-
self._compliant_expr, "dt", "to_string", format=format
17+
return self._compliant_expr._reuse_series_namespace_implementation(
18+
"dt", "to_string", format=format
2119
)
2220

2321
def replace_time_zone(self: Self, time_zone: str | None) -> ArrowExpr:
24-
return reuse_series_namespace_implementation(
25-
self._compliant_expr, "dt", "replace_time_zone", time_zone=time_zone
22+
return self._compliant_expr._reuse_series_namespace_implementation(
23+
"dt", "replace_time_zone", time_zone=time_zone
2624
)
2725

2826
def convert_time_zone(self: Self, time_zone: str) -> ArrowExpr:
29-
return reuse_series_namespace_implementation(
30-
self._compliant_expr, "dt", "convert_time_zone", time_zone=time_zone
27+
return self._compliant_expr._reuse_series_namespace_implementation(
28+
"dt", "convert_time_zone", time_zone=time_zone
3129
)
3230

3331
def timestamp(self: Self, time_unit: TimeUnit) -> ArrowExpr:
34-
return reuse_series_namespace_implementation(
35-
self._compliant_expr, "dt", "timestamp", time_unit=time_unit
32+
return self._compliant_expr._reuse_series_namespace_implementation(
33+
"dt", "timestamp", time_unit=time_unit
3634
)
3735

3836
def date(self: Self) -> ArrowExpr:
39-
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "date")
37+
return self._compliant_expr._reuse_series_namespace_implementation("dt", "date")
4038

4139
def year(self: Self) -> ArrowExpr:
42-
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "year")
40+
return self._compliant_expr._reuse_series_namespace_implementation("dt", "year")
4341

4442
def month(self: Self) -> ArrowExpr:
45-
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "month")
43+
return self._compliant_expr._reuse_series_namespace_implementation("dt", "month")
4644

4745
def day(self: Self) -> ArrowExpr:
48-
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "day")
46+
return self._compliant_expr._reuse_series_namespace_implementation("dt", "day")
4947

5048
def hour(self: Self) -> ArrowExpr:
51-
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "hour")
49+
return self._compliant_expr._reuse_series_namespace_implementation("dt", "hour")
5250

5351
def minute(self: Self) -> ArrowExpr:
54-
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "minute")
52+
return self._compliant_expr._reuse_series_namespace_implementation("dt", "minute")
5553

5654
def second(self: Self) -> ArrowExpr:
57-
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "second")
55+
return self._compliant_expr._reuse_series_namespace_implementation("dt", "second")
5856

5957
def millisecond(self: Self) -> ArrowExpr:
60-
return reuse_series_namespace_implementation(
61-
self._compliant_expr, "dt", "millisecond"
58+
return self._compliant_expr._reuse_series_namespace_implementation(
59+
"dt", "millisecond"
6260
)
6361

6462
def microsecond(self: Self) -> ArrowExpr:
65-
return reuse_series_namespace_implementation(
66-
self._compliant_expr, "dt", "microsecond"
63+
return self._compliant_expr._reuse_series_namespace_implementation(
64+
"dt", "microsecond"
6765
)
6866

6967
def nanosecond(self: Self) -> ArrowExpr:
70-
return reuse_series_namespace_implementation(
71-
self._compliant_expr, "dt", "nanosecond"
68+
return self._compliant_expr._reuse_series_namespace_implementation(
69+
"dt", "nanosecond"
7270
)
7371

7472
def ordinal_day(self: Self) -> ArrowExpr:
75-
return reuse_series_namespace_implementation(
76-
self._compliant_expr, "dt", "ordinal_day"
73+
return self._compliant_expr._reuse_series_namespace_implementation(
74+
"dt", "ordinal_day"
7775
)
7876

7977
def weekday(self: Self) -> ArrowExpr:
80-
return reuse_series_namespace_implementation(
81-
self._compliant_expr, "dt", "weekday"
78+
return self._compliant_expr._reuse_series_namespace_implementation(
79+
"dt", "weekday"
8280
)
8381

8482
def total_minutes(self: Self) -> ArrowExpr:
85-
return reuse_series_namespace_implementation(
86-
self._compliant_expr, "dt", "total_minutes"
83+
return self._compliant_expr._reuse_series_namespace_implementation(
84+
"dt", "total_minutes"
8785
)
8886

8987
def total_seconds(self: Self) -> ArrowExpr:
90-
return reuse_series_namespace_implementation(
91-
self._compliant_expr, "dt", "total_seconds"
88+
return self._compliant_expr._reuse_series_namespace_implementation(
89+
"dt", "total_seconds"
9290
)
9391

9492
def total_milliseconds(self: Self) -> ArrowExpr:
95-
return reuse_series_namespace_implementation(
96-
self._compliant_expr, "dt", "total_milliseconds"
93+
return self._compliant_expr._reuse_series_namespace_implementation(
94+
"dt", "total_milliseconds"
9795
)
9896

9997
def total_microseconds(self: Self) -> ArrowExpr:
100-
return reuse_series_namespace_implementation(
101-
self._compliant_expr, "dt", "total_microseconds"
98+
return self._compliant_expr._reuse_series_namespace_implementation(
99+
"dt", "total_microseconds"
102100
)
103101

104102
def total_nanoseconds(self: Self) -> ArrowExpr:
105-
return reuse_series_namespace_implementation(
106-
self._compliant_expr, "dt", "total_nanoseconds"
103+
return self._compliant_expr._reuse_series_namespace_implementation(
104+
"dt", "total_nanoseconds"
107105
)

narwhals/_arrow/expr_list.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from typing import TYPE_CHECKING
44

5-
from narwhals._expression_parsing import reuse_series_namespace_implementation
6-
75
if TYPE_CHECKING:
86
from typing_extensions import Self
97

@@ -15,4 +13,4 @@ def __init__(self: Self, expr: ArrowExpr) -> None:
1513
self._expr = expr
1614

1715
def len(self: Self) -> ArrowExpr:
18-
return reuse_series_namespace_implementation(self._expr, "list", "len")
16+
return self._expr._reuse_series_namespace_implementation("list", "len")

narwhals/_arrow/expr_str.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from typing import TYPE_CHECKING
44

5-
from narwhals._expression_parsing import reuse_series_namespace_implementation
6-
75
if TYPE_CHECKING:
86
from typing_extensions import Self
97

@@ -15,15 +13,14 @@ def __init__(self: Self, expr: ArrowExpr) -> None:
1513
self._compliant_expr = expr
1614

1715
def len_chars(self: Self) -> ArrowExpr:
18-
return reuse_series_namespace_implementation(
19-
self._compliant_expr, "str", "len_chars"
16+
return self._compliant_expr._reuse_series_namespace_implementation(
17+
"str", "len_chars"
2018
)
2119

2220
def replace(
2321
self: Self, pattern: str, value: str, *, literal: bool, n: int
2422
) -> ArrowExpr:
25-
return reuse_series_namespace_implementation(
26-
self._compliant_expr,
23+
return self._compliant_expr._reuse_series_namespace_implementation(
2724
"str",
2825
"replace",
2926
pattern=pattern,
@@ -33,8 +30,7 @@ def replace(
3330
)
3431

3532
def replace_all(self: Self, pattern: str, value: str, *, literal: bool) -> ArrowExpr:
36-
return reuse_series_namespace_implementation(
37-
self._compliant_expr,
33+
return self._compliant_expr._reuse_series_namespace_implementation(
3834
"str",
3935
"replace_all",
4036
pattern=pattern,
@@ -43,46 +39,46 @@ def replace_all(self: Self, pattern: str, value: str, *, literal: bool) -> Arrow
4339
)
4440

4541
def strip_chars(self: Self, characters: str | None) -> ArrowExpr:
46-
return reuse_series_namespace_implementation(
47-
self._compliant_expr, "str", "strip_chars", characters=characters
42+
return self._compliant_expr._reuse_series_namespace_implementation(
43+
"str", "strip_chars", characters=characters
4844
)
4945

5046
def starts_with(self: Self, prefix: str) -> ArrowExpr:
51-
return reuse_series_namespace_implementation(
52-
self._compliant_expr, "str", "starts_with", prefix=prefix
47+
return self._compliant_expr._reuse_series_namespace_implementation(
48+
"str", "starts_with", prefix=prefix
5349
)
5450

5551
def ends_with(self: Self, suffix: str) -> ArrowExpr:
56-
return reuse_series_namespace_implementation(
57-
self._compliant_expr, "str", "ends_with", suffix=suffix
52+
return self._compliant_expr._reuse_series_namespace_implementation(
53+
"str", "ends_with", suffix=suffix
5854
)
5955

6056
def contains(self: Self, pattern: str, *, literal: bool) -> ArrowExpr:
61-
return reuse_series_namespace_implementation(
62-
self._compliant_expr, "str", "contains", pattern=pattern, literal=literal
57+
return self._compliant_expr._reuse_series_namespace_implementation(
58+
"str", "contains", pattern=pattern, literal=literal
6359
)
6460

6561
def slice(self: Self, offset: int, length: int | None) -> ArrowExpr:
66-
return reuse_series_namespace_implementation(
67-
self._compliant_expr, "str", "slice", offset=offset, length=length
62+
return self._compliant_expr._reuse_series_namespace_implementation(
63+
"str", "slice", offset=offset, length=length
6864
)
6965

7066
def split(self: Self, by: str) -> ArrowExpr:
71-
return reuse_series_namespace_implementation(
72-
self._compliant_expr, "str", "split", by=by
67+
return self._compliant_expr._reuse_series_namespace_implementation(
68+
"str", "split", by=by
7369
)
7470

7571
def to_datetime(self: Self, format: str | None) -> ArrowExpr: # noqa: A002
76-
return reuse_series_namespace_implementation(
77-
self._compliant_expr, "str", "to_datetime", format=format
72+
return self._compliant_expr._reuse_series_namespace_implementation(
73+
"str", "to_datetime", format=format
7874
)
7975

8076
def to_uppercase(self: Self) -> ArrowExpr:
81-
return reuse_series_namespace_implementation(
82-
self._compliant_expr, "str", "to_uppercase"
77+
return self._compliant_expr._reuse_series_namespace_implementation(
78+
"str", "to_uppercase"
8379
)
8480

8581
def to_lowercase(self: Self) -> ArrowExpr:
86-
return reuse_series_namespace_implementation(
87-
self._compliant_expr, "str", "to_lowercase"
82+
return self._compliant_expr._reuse_series_namespace_implementation(
83+
"str", "to_lowercase"
8884
)

0 commit comments

Comments
 (0)