Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7935354
chore: Add `_StoresNative` protocol
dangotbanned Feb 26, 2025
732b78f
refactor: replace `ArrowSeries`
dangotbanned Feb 26, 2025
6118d66
refactor: replace `ArrowSeries*Namespace`
dangotbanned Feb 26, 2025
1b5edad
chore: add `_StoresCompliant`
dangotbanned Feb 26, 2025
7b8e22f
refactor: simplifying w/ `ArrowSeriesNamespace`
dangotbanned Feb 26, 2025
f725248
refactor: add & replace w/ `ArrowExprNamespace`
dangotbanned Feb 26, 2025
fb1c9f2
refactor: move up a level, add `PandasLikeSeries.native`
dangotbanned Feb 26, 2025
ee493b0
Merge remote-tracking branch 'upstream/main' into stores-native-compl…
dangotbanned Mar 2, 2025
3c0a9d4
test: Get coverage for `PandasLikeSeries.native`
dangotbanned Mar 2, 2025
342d629
fix: Make `PolarsSeries` compliant
dangotbanned Mar 2, 2025
d8df253
refactor: add `_SeriesNamespace.from_native`
dangotbanned Mar 2, 2025
d99a8b4
refactor: Simplify `_arrow.series_dt`
dangotbanned Mar 2, 2025
2fe5a64
refactor: simplify `_arrow.utils`
dangotbanned Mar 2, 2025
d7385bf
Merge remote-tracking branch 'upstream/main' into stores-native-compl…
dangotbanned Mar 2, 2025
66aab02
Merge remote-tracking branch 'upstream/main' into stores-native-compl…
dangotbanned Mar 2, 2025
ffa5396
Merge remote-tracking branch 'upstream/main' into stores-native-compl…
dangotbanned Mar 2, 2025
5c642eb
Merge branch 'main' into stores-native-compliant
dangotbanned Mar 2, 2025
39d4be8
Merge branch 'main' into stores-native-compliant
dangotbanned Mar 3, 2025
8192589
Merge branch 'main' into stores-native-compliant
dangotbanned Mar 3, 2025
ad62268
Merge branch 'main' into stores-native-compliant
dangotbanned Mar 3, 2025
3b467e1
Merge branch 'main' into stores-native-compliant
dangotbanned Mar 4, 2025
7c7a929
Merge remote-tracking branch 'upstream/main' into stores-native-compl…
dangotbanned Mar 5, 2025
5ff4f7c
Merge branch 'main' into stores-native-compliant
dangotbanned Mar 6, 2025
6676341
Merge remote-tracking branch 'upstream/main' into stores-native-compl…
dangotbanned Mar 6, 2025
946b11c
Merge remote-tracking branch 'upstream/main' into stores-native-compl…
dangotbanned Mar 8, 2025
7c4dea3
docs: "narwhals object" -> "compliant object"
dangotbanned Mar 8, 2025
0d41a7a
docs: Show examples of native/compliant
dangotbanned Mar 8, 2025
0921f33
docs: fix typo
dangotbanned Mar 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions narwhals/_arrow/expr_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import TYPE_CHECKING

from narwhals._arrow.utils import ArrowExprNamespace
from narwhals._expression_parsing import reuse_series_namespace_implementation

if TYPE_CHECKING:
Expand All @@ -10,11 +11,8 @@
from narwhals._arrow.expr import ArrowExpr


class ArrowExprCatNamespace:
def __init__(self: Self, expr: ArrowExpr) -> None:
self._compliant_expr = expr

class ArrowExprCatNamespace(ArrowExprNamespace):
def get_categories(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "cat", "get_categories"
self.compliant, "cat", "get_categories"
)
58 changes: 23 additions & 35 deletions narwhals/_arrow/expr_dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import TYPE_CHECKING

from narwhals._arrow.utils import ArrowExprNamespace
from narwhals._expression_parsing import reuse_series_namespace_implementation

if TYPE_CHECKING:
Expand All @@ -11,97 +12,84 @@
from narwhals.typing import TimeUnit


class ArrowExprDateTimeNamespace:
def __init__(self: Self, expr: ArrowExpr) -> None:
self._compliant_expr = expr

class ArrowExprDateTimeNamespace(ArrowExprNamespace):
def to_string(self: Self, format: str) -> ArrowExpr: # noqa: A002
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "to_string", format=format
self.compliant, "dt", "to_string", format=format
)

def replace_time_zone(self: Self, time_zone: str | None) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "replace_time_zone", time_zone=time_zone
self.compliant, "dt", "replace_time_zone", time_zone=time_zone
)

def convert_time_zone(self: Self, time_zone: str) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "convert_time_zone", time_zone=time_zone
self.compliant, "dt", "convert_time_zone", time_zone=time_zone
)

def timestamp(self: Self, time_unit: TimeUnit) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "timestamp", time_unit=time_unit
self.compliant, "dt", "timestamp", time_unit=time_unit
)

def date(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "date")
return reuse_series_namespace_implementation(self.compliant, "dt", "date")

def year(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "year")
return reuse_series_namespace_implementation(self.compliant, "dt", "year")

def month(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "month")
return reuse_series_namespace_implementation(self.compliant, "dt", "month")

def day(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "day")
return reuse_series_namespace_implementation(self.compliant, "dt", "day")

def hour(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "hour")
return reuse_series_namespace_implementation(self.compliant, "dt", "hour")

def minute(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "minute")
return reuse_series_namespace_implementation(self.compliant, "dt", "minute")

def second(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(self._compliant_expr, "dt", "second")
return reuse_series_namespace_implementation(self.compliant, "dt", "second")

def millisecond(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "millisecond"
)
return reuse_series_namespace_implementation(self.compliant, "dt", "millisecond")

def microsecond(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "microsecond"
)
return reuse_series_namespace_implementation(self.compliant, "dt", "microsecond")

def nanosecond(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "nanosecond"
)
return reuse_series_namespace_implementation(self.compliant, "dt", "nanosecond")

def ordinal_day(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "ordinal_day"
)
return reuse_series_namespace_implementation(self.compliant, "dt", "ordinal_day")

def weekday(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "weekday"
)
return reuse_series_namespace_implementation(self.compliant, "dt", "weekday")

def total_minutes(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "total_minutes"
self.compliant, "dt", "total_minutes"
)

def total_seconds(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "total_seconds"
self.compliant, "dt", "total_seconds"
)

def total_milliseconds(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "total_milliseconds"
self.compliant, "dt", "total_milliseconds"
)

def total_microseconds(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "total_microseconds"
self.compliant, "dt", "total_microseconds"
)

def total_nanoseconds(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "dt", "total_nanoseconds"
self.compliant, "dt", "total_nanoseconds"
)
8 changes: 3 additions & 5 deletions narwhals/_arrow/expr_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import TYPE_CHECKING

from narwhals._arrow.utils import ArrowExprNamespace
from narwhals._expression_parsing import reuse_series_namespace_implementation

if TYPE_CHECKING:
Expand All @@ -10,9 +11,6 @@
from narwhals._arrow.expr import ArrowExpr


class ArrowExprListNamespace:
def __init__(self: Self, expr: ArrowExpr) -> None:
self._expr = expr

class ArrowExprListNamespace(ArrowExprNamespace):
def len(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(self._expr, "list", "len")
return reuse_series_namespace_implementation(self.compliant, "list", "len")
24 changes: 11 additions & 13 deletions narwhals/_arrow/expr_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
from typing import Callable
from typing import Sequence

from narwhals._arrow.utils import ArrowExprNamespace

if TYPE_CHECKING:
from typing_extensions import Self

from narwhals._arrow.expr import ArrowExpr


class ArrowExprNameNamespace:
def __init__(self: Self, expr: ArrowExpr) -> None:
self._compliant_expr = expr

class ArrowExprNameNamespace(ArrowExprNamespace):
def keep(self: Self) -> ArrowExpr:
return self._from_colname_func_and_alias_output_names(
name_mapping_func=lambda name: name,
Expand Down Expand Up @@ -65,19 +64,18 @@ def _from_colname_func_and_alias_output_names(
name_mapping_func: Callable[[str], str],
alias_output_names: Callable[[Sequence[str]], Sequence[str]] | None,
) -> ArrowExpr:
return self._compliant_expr.__class__(
return self.compliant.__class__(
call=lambda df: [
series.alias(name_mapping_func(name))
for series, name in zip(
self._compliant_expr._call(df),
self._compliant_expr._evaluate_output_names(df),
self.compliant._call(df), self.compliant._evaluate_output_names(df)
)
],
depth=self._compliant_expr._depth,
function_name=self._compliant_expr._function_name,
evaluate_output_names=self._compliant_expr._evaluate_output_names,
depth=self.compliant._depth,
function_name=self.compliant._function_name,
evaluate_output_names=self.compliant._evaluate_output_names,
alias_output_names=alias_output_names,
backend_version=self._compliant_expr._backend_version,
version=self._compliant_expr._version,
call_kwargs=self._compliant_expr._call_kwargs,
backend_version=self.compliant._backend_version,
version=self.compliant._version,
call_kwargs=self.compliant._call_kwargs,
)
30 changes: 13 additions & 17 deletions narwhals/_arrow/expr_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import TYPE_CHECKING

from narwhals._arrow.utils import ArrowExprNamespace
from narwhals._expression_parsing import reuse_series_namespace_implementation

if TYPE_CHECKING:
Expand All @@ -10,20 +11,15 @@
from narwhals._arrow.expr import ArrowExpr


class ArrowExprStringNamespace:
def __init__(self: Self, expr: ArrowExpr) -> None:
self._compliant_expr = expr

class ArrowExprStringNamespace(ArrowExprNamespace):
def len_chars(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "str", "len_chars"
)
return reuse_series_namespace_implementation(self.compliant, "str", "len_chars")

def replace(
self: Self, pattern: str, value: str, *, literal: bool, n: int
) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr,
self.compliant,
"str",
"replace",
pattern=pattern,
Expand All @@ -34,7 +30,7 @@ def replace(

def replace_all(self: Self, pattern: str, value: str, *, literal: bool) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr,
self.compliant,
"str",
"replace_all",
pattern=pattern,
Expand All @@ -44,27 +40,27 @@ def replace_all(self: Self, pattern: str, value: str, *, literal: bool) -> Arrow

def strip_chars(self: Self, characters: str | None) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "str", "strip_chars", characters=characters
self.compliant, "str", "strip_chars", characters=characters
)

def starts_with(self: Self, prefix: str) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "str", "starts_with", prefix=prefix
self.compliant, "str", "starts_with", prefix=prefix
)

def ends_with(self: Self, suffix: str) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "str", "ends_with", suffix=suffix
self.compliant, "str", "ends_with", suffix=suffix
)

def contains(self: Self, pattern: str, *, literal: bool) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "str", "contains", pattern=pattern, literal=literal
self.compliant, "str", "contains", pattern=pattern, literal=literal
)

def slice(self: Self, offset: int, length: int | None) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "str", "slice", offset=offset, length=length
self.compliant, "str", "slice", offset=offset, length=length
)

def split(self: Self, by: str) -> ArrowExpr:
Expand All @@ -74,15 +70,15 @@ def split(self: Self, by: str) -> ArrowExpr:

def to_datetime(self: Self, format: str | None) -> ArrowExpr: # noqa: A002
return reuse_series_namespace_implementation(
self._compliant_expr, "str", "to_datetime", format=format
self.compliant, "str", "to_datetime", format=format
)

def to_uppercase(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "str", "to_uppercase"
self.compliant, "str", "to_uppercase"
)

def to_lowercase(self: Self) -> ArrowExpr:
return reuse_series_namespace_implementation(
self._compliant_expr, "str", "to_lowercase"
self.compliant, "str", "to_lowercase"
)
Loading
Loading