Skip to content

Commit 00a3442

Browse files
committed
refactor: remove implementation from method names
The docs already provide a description
1 parent 6ce86c3 commit 00a3442

File tree

11 files changed

+155
-246
lines changed

11 files changed

+155
-246
lines changed

narwhals/_arrow/expr.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ def _reuse_series_extra_kwargs(
138138
return {"_return_py_scalar": False} if returns_scalar else {}
139139

140140
def cum_sum(self: Self, *, reverse: bool) -> Self:
141-
return self._reuse_series_implementation("cum_sum", reverse=reverse)
141+
return self._reuse_series("cum_sum", reverse=reverse)
142142

143143
def shift(self: Self, n: int) -> Self:
144-
return self._reuse_series_implementation("shift", n=n)
144+
return self._reuse_series("shift", n=n)
145145

146146
def over(self: Self, keys: Sequence[str], kind: ExprKind) -> Self:
147147
if not is_scalar_like(kind):
@@ -215,26 +215,24 @@ def func(df: ArrowDataFrame) -> list[ArrowSeries]:
215215
)
216216

217217
def cum_count(self: Self, *, reverse: bool) -> Self:
218-
return self._reuse_series_implementation("cum_count", reverse=reverse)
218+
return self._reuse_series("cum_count", reverse=reverse)
219219

220220
def cum_min(self: Self, *, reverse: bool) -> Self:
221-
return self._reuse_series_implementation("cum_min", reverse=reverse)
221+
return self._reuse_series("cum_min", reverse=reverse)
222222

223223
def cum_max(self: Self, *, reverse: bool) -> Self:
224-
return self._reuse_series_implementation("cum_max", reverse=reverse)
224+
return self._reuse_series("cum_max", reverse=reverse)
225225

226226
def cum_prod(self: Self, *, reverse: bool) -> Self:
227-
return self._reuse_series_implementation("cum_prod", reverse=reverse)
227+
return self._reuse_series("cum_prod", reverse=reverse)
228228

229229
def rank(
230230
self: Self,
231231
method: Literal["average", "min", "max", "dense", "ordinal"],
232232
*,
233233
descending: bool,
234234
) -> Self:
235-
return self._reuse_series_implementation(
236-
"rank", method=method, descending=descending
237-
)
235+
return self._reuse_series("rank", method=method, descending=descending)
238236

239237
ewm_mean = not_implemented()
240238

narwhals/_arrow/expr_cat.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,4 @@ def __init__(self: Self, expr: ArrowExpr) -> None:
1313
self._compliant_expr = expr
1414

1515
def get_categories(self: Self) -> ArrowExpr:
16-
return self._compliant_expr._reuse_series_namespace_implementation(
17-
"cat", "get_categories"
18-
)
16+
return self._compliant_expr._reuse_series_namespace("cat", "get_categories")

narwhals/_arrow/expr_dt.py

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,92 +14,72 @@ def __init__(self: Self, expr: ArrowExpr) -> None:
1414
self._compliant_expr = expr
1515

1616
def to_string(self: Self, format: str) -> ArrowExpr: # noqa: A002
17-
return self._compliant_expr._reuse_series_namespace_implementation(
17+
return self._compliant_expr._reuse_series_namespace(
1818
"dt", "to_string", format=format
1919
)
2020

2121
def replace_time_zone(self: Self, time_zone: str | None) -> ArrowExpr:
22-
return self._compliant_expr._reuse_series_namespace_implementation(
22+
return self._compliant_expr._reuse_series_namespace(
2323
"dt", "replace_time_zone", time_zone=time_zone
2424
)
2525

2626
def convert_time_zone(self: Self, time_zone: str) -> ArrowExpr:
27-
return self._compliant_expr._reuse_series_namespace_implementation(
27+
return self._compliant_expr._reuse_series_namespace(
2828
"dt", "convert_time_zone", time_zone=time_zone
2929
)
3030

3131
def timestamp(self: Self, time_unit: TimeUnit) -> ArrowExpr:
32-
return self._compliant_expr._reuse_series_namespace_implementation(
32+
return self._compliant_expr._reuse_series_namespace(
3333
"dt", "timestamp", time_unit=time_unit
3434
)
3535

3636
def date(self: Self) -> ArrowExpr:
37-
return self._compliant_expr._reuse_series_namespace_implementation("dt", "date")
37+
return self._compliant_expr._reuse_series_namespace("dt", "date")
3838

3939
def year(self: Self) -> ArrowExpr:
40-
return self._compliant_expr._reuse_series_namespace_implementation("dt", "year")
40+
return self._compliant_expr._reuse_series_namespace("dt", "year")
4141

4242
def month(self: Self) -> ArrowExpr:
43-
return self._compliant_expr._reuse_series_namespace_implementation("dt", "month")
43+
return self._compliant_expr._reuse_series_namespace("dt", "month")
4444

4545
def day(self: Self) -> ArrowExpr:
46-
return self._compliant_expr._reuse_series_namespace_implementation("dt", "day")
46+
return self._compliant_expr._reuse_series_namespace("dt", "day")
4747

4848
def hour(self: Self) -> ArrowExpr:
49-
return self._compliant_expr._reuse_series_namespace_implementation("dt", "hour")
49+
return self._compliant_expr._reuse_series_namespace("dt", "hour")
5050

5151
def minute(self: Self) -> ArrowExpr:
52-
return self._compliant_expr._reuse_series_namespace_implementation("dt", "minute")
52+
return self._compliant_expr._reuse_series_namespace("dt", "minute")
5353

5454
def second(self: Self) -> ArrowExpr:
55-
return self._compliant_expr._reuse_series_namespace_implementation("dt", "second")
55+
return self._compliant_expr._reuse_series_namespace("dt", "second")
5656

5757
def millisecond(self: Self) -> ArrowExpr:
58-
return self._compliant_expr._reuse_series_namespace_implementation(
59-
"dt", "millisecond"
60-
)
58+
return self._compliant_expr._reuse_series_namespace("dt", "millisecond")
6159

6260
def microsecond(self: Self) -> ArrowExpr:
63-
return self._compliant_expr._reuse_series_namespace_implementation(
64-
"dt", "microsecond"
65-
)
61+
return self._compliant_expr._reuse_series_namespace("dt", "microsecond")
6662

6763
def nanosecond(self: Self) -> ArrowExpr:
68-
return self._compliant_expr._reuse_series_namespace_implementation(
69-
"dt", "nanosecond"
70-
)
64+
return self._compliant_expr._reuse_series_namespace("dt", "nanosecond")
7165

7266
def ordinal_day(self: Self) -> ArrowExpr:
73-
return self._compliant_expr._reuse_series_namespace_implementation(
74-
"dt", "ordinal_day"
75-
)
67+
return self._compliant_expr._reuse_series_namespace("dt", "ordinal_day")
7668

7769
def weekday(self: Self) -> ArrowExpr:
78-
return self._compliant_expr._reuse_series_namespace_implementation(
79-
"dt", "weekday"
80-
)
70+
return self._compliant_expr._reuse_series_namespace("dt", "weekday")
8171

8272
def total_minutes(self: Self) -> ArrowExpr:
83-
return self._compliant_expr._reuse_series_namespace_implementation(
84-
"dt", "total_minutes"
85-
)
73+
return self._compliant_expr._reuse_series_namespace("dt", "total_minutes")
8674

8775
def total_seconds(self: Self) -> ArrowExpr:
88-
return self._compliant_expr._reuse_series_namespace_implementation(
89-
"dt", "total_seconds"
90-
)
76+
return self._compliant_expr._reuse_series_namespace("dt", "total_seconds")
9177

9278
def total_milliseconds(self: Self) -> ArrowExpr:
93-
return self._compliant_expr._reuse_series_namespace_implementation(
94-
"dt", "total_milliseconds"
95-
)
79+
return self._compliant_expr._reuse_series_namespace("dt", "total_milliseconds")
9680

9781
def total_microseconds(self: Self) -> ArrowExpr:
98-
return self._compliant_expr._reuse_series_namespace_implementation(
99-
"dt", "total_microseconds"
100-
)
82+
return self._compliant_expr._reuse_series_namespace("dt", "total_microseconds")
10183

10284
def total_nanoseconds(self: Self) -> ArrowExpr:
103-
return self._compliant_expr._reuse_series_namespace_implementation(
104-
"dt", "total_nanoseconds"
105-
)
85+
return self._compliant_expr._reuse_series_namespace("dt", "total_nanoseconds")

narwhals/_arrow/expr_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ def __init__(self: Self, expr: ArrowExpr) -> None:
1313
self._expr = expr
1414

1515
def len(self: Self) -> ArrowExpr:
16-
return self._expr._reuse_series_namespace_implementation("list", "len")
16+
return self._expr._reuse_series_namespace("list", "len")

narwhals/_arrow/expr_str.py

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,72 +13,55 @@ def __init__(self: Self, expr: ArrowExpr) -> None:
1313
self._compliant_expr = expr
1414

1515
def len_chars(self: Self) -> ArrowExpr:
16-
return self._compliant_expr._reuse_series_namespace_implementation(
17-
"str", "len_chars"
18-
)
16+
return self._compliant_expr._reuse_series_namespace("str", "len_chars")
1917

2018
def replace(
2119
self: Self, pattern: str, value: str, *, literal: bool, n: int
2220
) -> ArrowExpr:
23-
return self._compliant_expr._reuse_series_namespace_implementation(
24-
"str",
25-
"replace",
26-
pattern=pattern,
27-
value=value,
28-
literal=literal,
29-
n=n,
21+
return self._compliant_expr._reuse_series_namespace(
22+
"str", "replace", pattern=pattern, value=value, literal=literal, n=n
3023
)
3124

3225
def replace_all(self: Self, pattern: str, value: str, *, literal: bool) -> ArrowExpr:
33-
return self._compliant_expr._reuse_series_namespace_implementation(
34-
"str",
35-
"replace_all",
36-
pattern=pattern,
37-
value=value,
38-
literal=literal,
26+
return self._compliant_expr._reuse_series_namespace(
27+
"str", "replace_all", pattern=pattern, value=value, literal=literal
3928
)
4029

4130
def strip_chars(self: Self, characters: str | None) -> ArrowExpr:
42-
return self._compliant_expr._reuse_series_namespace_implementation(
31+
return self._compliant_expr._reuse_series_namespace(
4332
"str", "strip_chars", characters=characters
4433
)
4534

4635
def starts_with(self: Self, prefix: str) -> ArrowExpr:
47-
return self._compliant_expr._reuse_series_namespace_implementation(
36+
return self._compliant_expr._reuse_series_namespace(
4837
"str", "starts_with", prefix=prefix
4938
)
5039

5140
def ends_with(self: Self, suffix: str) -> ArrowExpr:
52-
return self._compliant_expr._reuse_series_namespace_implementation(
41+
return self._compliant_expr._reuse_series_namespace(
5342
"str", "ends_with", suffix=suffix
5443
)
5544

5645
def contains(self: Self, pattern: str, *, literal: bool) -> ArrowExpr:
57-
return self._compliant_expr._reuse_series_namespace_implementation(
46+
return self._compliant_expr._reuse_series_namespace(
5847
"str", "contains", pattern=pattern, literal=literal
5948
)
6049

6150
def slice(self: Self, offset: int, length: int | None) -> ArrowExpr:
62-
return self._compliant_expr._reuse_series_namespace_implementation(
51+
return self._compliant_expr._reuse_series_namespace(
6352
"str", "slice", offset=offset, length=length
6453
)
6554

6655
def split(self: Self, by: str) -> ArrowExpr:
67-
return self._compliant_expr._reuse_series_namespace_implementation(
68-
"str", "split", by=by
69-
)
56+
return self._compliant_expr._reuse_series_namespace("str", "split", by=by)
7057

7158
def to_datetime(self: Self, format: str | None) -> ArrowExpr: # noqa: A002
72-
return self._compliant_expr._reuse_series_namespace_implementation(
59+
return self._compliant_expr._reuse_series_namespace(
7360
"str", "to_datetime", format=format
7461
)
7562

7663
def to_uppercase(self: Self) -> ArrowExpr:
77-
return self._compliant_expr._reuse_series_namespace_implementation(
78-
"str", "to_uppercase"
79-
)
64+
return self._compliant_expr._reuse_series_namespace("str", "to_uppercase")
8065

8166
def to_lowercase(self: Self) -> ArrowExpr:
82-
return self._compliant_expr._reuse_series_namespace_implementation(
83-
"str", "to_lowercase"
84-
)
67+
return self._compliant_expr._reuse_series_namespace("str", "to_lowercase")

0 commit comments

Comments
 (0)