Skip to content

Commit 5a13b63

Browse files
committed
feat: Super reusable namespaces 🤯
Only `.name` differs between the two `EagerExpr` - so why not share?
1 parent 612df69 commit 5a13b63

File tree

13 files changed

+247
-399
lines changed

13 files changed

+247
-399
lines changed

narwhals/_arrow/expr.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88

99
import pyarrow.compute as pc
1010

11-
from narwhals._arrow.expr_cat import ArrowExprCatNamespace
12-
from narwhals._arrow.expr_dt import ArrowExprDateTimeNamespace
13-
from narwhals._arrow.expr_list import ArrowExprListNamespace
1411
from narwhals._arrow.expr_name import ArrowExprNameNamespace
15-
from narwhals._arrow.expr_str import ArrowExprStringNamespace
1612
from narwhals._arrow.series import ArrowSeries
1713
from narwhals._compliant import EagerExpr
1814
from narwhals._expression_parsing import ExprKind
@@ -268,22 +264,6 @@ def rank(
268264

269265
ewm_mean = not_implemented()
270266

271-
@property
272-
def dt(self: Self) -> ArrowExprDateTimeNamespace:
273-
return ArrowExprDateTimeNamespace(self)
274-
275-
@property
276-
def str(self: Self) -> ArrowExprStringNamespace:
277-
return ArrowExprStringNamespace(self)
278-
279-
@property
280-
def cat(self: Self) -> ArrowExprCatNamespace:
281-
return ArrowExprCatNamespace(self)
282-
283267
@property
284268
def name(self: Self) -> ArrowExprNameNamespace:
285269
return ArrowExprNameNamespace(self)
286-
287-
@property
288-
def list(self: Self) -> ArrowExprListNamespace:
289-
return ArrowExprListNamespace(self)

narwhals/_arrow/expr_cat.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

narwhals/_arrow/expr_dt.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

narwhals/_arrow/expr_list.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

narwhals/_arrow/expr_str.py

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
from typing import Protocol
5+
6+
from narwhals.utils import CompliantT_co
7+
from narwhals.utils import _StoresCompliant
8+
9+
if TYPE_CHECKING:
10+
from typing import Callable
11+
12+
from narwhals.typing import TimeUnit
13+
14+
__all__ = [
15+
"CatNamespace",
16+
"DateTimeNamespace",
17+
"ListNamespace",
18+
"NameNamespace",
19+
"StringNamespace",
20+
]
21+
22+
23+
class CatNamespace(_StoresCompliant[CompliantT_co], Protocol[CompliantT_co]):
24+
def get_categories(self) -> CompliantT_co: ...
25+
26+
27+
class DateTimeNamespace(_StoresCompliant[CompliantT_co], Protocol[CompliantT_co]):
28+
def to_string(self, format: str) -> CompliantT_co: ... # noqa: A002
29+
def replace_time_zone(self, time_zone: str | None) -> CompliantT_co: ...
30+
def convert_time_zone(self, time_zone: str) -> CompliantT_co: ...
31+
def timestamp(self, time_unit: TimeUnit) -> CompliantT_co: ...
32+
def date(self) -> CompliantT_co: ...
33+
def year(self) -> CompliantT_co: ...
34+
def month(self) -> CompliantT_co: ...
35+
def day(self) -> CompliantT_co: ...
36+
def hour(self) -> CompliantT_co: ...
37+
def minute(self) -> CompliantT_co: ...
38+
def second(self) -> CompliantT_co: ...
39+
def millisecond(self) -> CompliantT_co: ...
40+
def microsecond(self) -> CompliantT_co: ...
41+
def nanosecond(self) -> CompliantT_co: ...
42+
def ordinal_day(self) -> CompliantT_co: ...
43+
def weekday(self) -> CompliantT_co: ...
44+
def total_minutes(self) -> CompliantT_co: ...
45+
def total_seconds(self) -> CompliantT_co: ...
46+
def total_milliseconds(self) -> CompliantT_co: ...
47+
def total_microseconds(self) -> CompliantT_co: ...
48+
def total_nanoseconds(self) -> CompliantT_co: ...
49+
50+
51+
class ListNamespace(_StoresCompliant[CompliantT_co], Protocol[CompliantT_co]):
52+
def len(self) -> CompliantT_co: ...
53+
54+
55+
class NameNamespace(_StoresCompliant[CompliantT_co], Protocol[CompliantT_co]):
56+
def keep(self) -> CompliantT_co: ...
57+
def map(self, function: Callable[[str], str]) -> CompliantT_co: ...
58+
def prefix(self, prefix: str) -> CompliantT_co: ...
59+
def suffix(self, suffix: str) -> CompliantT_co: ...
60+
def to_lowercase(self) -> CompliantT_co: ...
61+
def to_uppercase(self) -> CompliantT_co: ...
62+
63+
64+
class StringNamespace(_StoresCompliant[CompliantT_co], Protocol[CompliantT_co]):
65+
def len_chars(self) -> CompliantT_co: ...
66+
def replace(
67+
self, pattern: str, value: str, *, literal: bool, n: int
68+
) -> CompliantT_co: ...
69+
def replace_all(
70+
self, pattern: str, value: str, *, literal: bool
71+
) -> CompliantT_co: ...
72+
def strip_chars(self, characters: str | None) -> CompliantT_co: ...
73+
def starts_with(self, prefix: str) -> CompliantT_co: ...
74+
def ends_with(self, suffix: str) -> CompliantT_co: ...
75+
def contains(self, pattern: str, *, literal: bool) -> CompliantT_co: ...
76+
def slice(self, offset: int, length: int | None) -> CompliantT_co: ...
77+
def split(self, by: str) -> CompliantT_co: ...
78+
def to_datetime(self, format: str | None) -> CompliantT_co: ... # noqa: A002
79+
def to_lowercase(self) -> CompliantT_co: ...
80+
def to_uppercase(self) -> CompliantT_co: ...

0 commit comments

Comments
 (0)