Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a9952f8
refactor: `.from_iterable`, `.native`, generic
dangotbanned Mar 17, 2025
3e0d816
refactor: Implement `__narwhals_series__`
dangotbanned Mar 17, 2025
9ac210f
refactor(RFC): `CompliantSeries._with_native`
dangotbanned Mar 17, 2025
1e90cc4
chore: Implement `__len__`
dangotbanned Mar 17, 2025
3918a0e
promote `cast`
dangotbanned Mar 17, 2025
3500aad
chore: `CompliantSeries` methods
dangotbanned Mar 17, 2025
1d89884
chore(DRAFT): `CompliantSeries` namespaces
dangotbanned Mar 17, 2025
54e2e9f
fix: Mark `ArrowSeries.ewm_mean` as `not_implemented`
dangotbanned Mar 17, 2025
7434d91
override `__(eq|ne)__`
dangotbanned Mar 17, 2025
3706534
fix(typing): `PandasLikeSeries.to_polars` return type
dangotbanned Mar 17, 2025
0f504d0
narrow partial generics
dangotbanned Mar 17, 2025
1554739
fix(typing): Satisfy `pyright`
dangotbanned Mar 17, 2025
9544a5d
fix(typing): Satisfy `mypy`
dangotbanned Mar 17, 2025
a38c9db
fix: revert and adapt `to_numpy`
dangotbanned Mar 17, 2025
b01fc41
Merge remote-tracking branch 'upstream/main' into compliant-series-spec
dangotbanned Mar 18, 2025
2d79d10
chore: remove some comments
dangotbanned Mar 18, 2025
f917105
refactor: use `is_compliant_series`
dangotbanned Mar 18, 2025
48169a4
Merge remote-tracking branch 'upstream/main' into compliant-series-spec
dangotbanned Mar 18, 2025
9e0611d
revert: remove `CompliantSeries._with_native`
dangotbanned Mar 18, 2025
eba34c1
Merge branch 'main' into compliant-series-spec
dangotbanned Mar 19, 2025
13b9b61
Merge remote-tracking branch 'upstream/main' into compliant-series-spec
dangotbanned Mar 19, 2025
2a37cb6
Merge remote-tracking branch 'upstream/main' into compliant-series-spec
dangotbanned Mar 19, 2025
5ff6936
resolve more conflicts
dangotbanned Mar 19, 2025
5ae44af
Merge branch 'main' into compliant-series-spec
dangotbanned Mar 19, 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
4 changes: 2 additions & 2 deletions narwhals/_arrow/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def len(self: Self) -> ArrowExpr:
# coverage bug? this is definitely hit
return self._expr( # pragma: no cover
lambda df: [
ArrowSeries._from_iterable(
ArrowSeries.from_iterable(
[len(df._native_frame)], name="len", context=self
)
],
Expand All @@ -79,7 +79,7 @@ def len(self: Self) -> ArrowExpr:

def lit(self: Self, value: Any, dtype: DType | None) -> ArrowExpr:
def _lit_arrow_series(_: ArrowDataFrame) -> ArrowSeries:
arrow_series = ArrowSeries._from_iterable(
arrow_series = ArrowSeries.from_iterable(
data=[value], name="literal", context=self
)
if dtype:
Expand Down
30 changes: 14 additions & 16 deletions narwhals/_arrow/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Iterable
from typing import Iterator
from typing import Literal
from typing import Mapping
from typing import Sequence
from typing import cast
from typing import overload
Expand Down Expand Up @@ -32,6 +33,7 @@
from narwhals.utils import Implementation
from narwhals.utils import generate_temporary_column_name
from narwhals.utils import import_dtypes_module
from narwhals.utils import not_implemented
from narwhals.utils import validate_backend_version

if TYPE_CHECKING:
Expand Down Expand Up @@ -139,12 +141,8 @@ def _from_native_series(
)

@classmethod
def _from_iterable(
cls: type[Self],
data: Iterable[Any],
name: str,
*,
context: _FullContext,
def from_iterable(
cls, data: Iterable[Any], *, context: _FullContext, name: str = ""
) -> Self:
return cls(
chunked_array([data]),
Expand All @@ -160,8 +158,8 @@ def _from_scalar(self, value: Any) -> Self:

@classmethod
def from_numpy(cls, data: Into1DArray, /, *, context: _FullContext) -> Self:
return cls._from_iterable(
data if is_numpy_array_1d(data) else [data], name="", context=context
return cls.from_iterable(
data if is_numpy_array_1d(data) else [data], context=context
)

def __narwhals_namespace__(self: Self) -> ArrowNamespace:
Expand All @@ -171,9 +169,6 @@ def __narwhals_namespace__(self: Self) -> ArrowNamespace:
backend_version=self._backend_version, version=self._version
)

def __len__(self: Self) -> int:
return len(self.native)

def __eq__(self: Self, other: object) -> Self: # type: ignore[override]
ser, other = extract_native(self, other)
return self._from_native_series(pc.equal(ser, other)) # type: ignore[arg-type]
Expand Down Expand Up @@ -391,9 +386,6 @@ def __native_namespace__(self: Self) -> ModuleType:
def name(self: Self) -> str:
return self._name

def __narwhals_series__(self: Self) -> Self:
return self

@overload
def __getitem__(self: Self, idx: int) -> Any: ...

Expand Down Expand Up @@ -569,7 +561,7 @@ def arg_true(self: Self) -> Self:
import numpy as np # ignore-banned-import

res = np.flatnonzero(self.native)
return self._from_iterable(res, name=self.name, context=self)
return self.from_iterable(res, name=self.name, context=self)

def item(self: Self, index: int | None = None) -> Any:
if index is None:
Expand Down Expand Up @@ -753,7 +745,11 @@ def unique(self: Self, *, maintain_order: bool) -> Self:
return self._from_native_series(self.native.unique())

def replace_strict(
self: Self, old: Sequence[Any], new: Sequence[Any], *, return_dtype: DType | None
self: Self,
old: Sequence[Any] | Mapping[Any, Any],
new: Sequence[Any],
*,
return_dtype: DType | type[DType] | None,
) -> Self:
# https://stackoverflow.com/a/79111029/4451315
idxs = pc.index_in(self.native, pa.array(old))
Expand Down Expand Up @@ -1217,3 +1213,5 @@ def list(self: Self) -> ArrowSeriesListNamespace:
@property
def struct(self: Self) -> ArrowSeriesStructNamespace:
return ArrowSeriesStructNamespace(self)

ewm_mean = not_implemented()
2 changes: 2 additions & 0 deletions narwhals/_compliant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from narwhals._compliant.typing import EagerSeriesT
from narwhals._compliant.typing import IntoCompliantExpr
from narwhals._compliant.typing import NativeFrameT_co
from narwhals._compliant.typing import NativeSeriesT_co

__all__ = [
"CompliantDataFrame",
Expand All @@ -50,4 +51,5 @@
"LazyExpr",
"LazySelectorNamespace",
"NativeFrameT_co",
"NativeSeriesT_co",
]
2 changes: 1 addition & 1 deletion narwhals/_compliant/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def quantile(
) -> Self: ...
def map_batches(
self,
function: Callable[[CompliantSeries], CompliantExpr[Any, Any]],
function: Callable[[CompliantSeries[Any]], CompliantExpr[Any, Any]],
return_dtype: DType | type[DType] | None,
) -> Self: ...

Expand Down
4 changes: 2 additions & 2 deletions narwhals/_compliant/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
]


SeriesOrExprT = TypeVar("SeriesOrExprT", bound="CompliantSeries | NativeExpr")
SeriesT = TypeVar("SeriesT", bound="CompliantSeries")
SeriesOrExprT = TypeVar("SeriesOrExprT", bound="CompliantSeries[Any] | NativeExpr")
SeriesT = TypeVar("SeriesT", bound="CompliantSeries[Any]")
ExprT = TypeVar("ExprT", bound="NativeExpr")
FrameT = TypeVar(
"FrameT", bound="CompliantDataFrame[Any, Any, Any] | CompliantLazyFrame[Any, Any]"
Expand Down
Loading
Loading