Skip to content

Commit eb04cc8

Browse files
authored
Merge branch 'main' into compliant-group-by
2 parents e84cb98 + 8aec8fa commit eb04cc8

File tree

20 files changed

+475
-151
lines changed

20 files changed

+475
-151
lines changed

.github/workflows/downstream_tests.yml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ jobs:
435435
run: |
436436
cd pointblank
437437
uv pip install --system ".[dev]"
438-
uv pip install pytest pytest-cov pytest-snapshot pandas polars "ibis-framework[duckdb,mysql,postgres,sqlite]>=9.5.0" chatlas --system
438+
uv pip install pytest pytest-cov pytest-snapshot pandas polars "ibis-framework[duckdb,mysql,postgres,sqlite]>=9.5.0" chatlas shiny --system
439439
- name: install-narwhals-dev
440440
run: |
441441
uv pip uninstall narwhals --system
@@ -472,29 +472,25 @@ jobs:
472472
- name: install-validoopsie-dev
473473
run: |
474474
cd validoopsie
475-
uv venv
476-
. .venv/bin/activate
477475
uv sync --dev
478-
uv pip install pytest-env
479-
which python
480-
- name: show-deps
476+
- name: install-narwhals-dev
481477
run: |
482478
cd validoopsie
483-
. .venv/bin/activate
484-
uv pip freeze
485-
- name: install-narwhals-dev
479+
uv remove narwhals
480+
uv add ./..
481+
- name: show-deps
486482
run: |
487483
cd validoopsie
488-
. .venv/bin/activate
489-
uv pip uninstall narwhals
490-
uv pip install -e ./..
484+
which python
485+
uv pip freeze
491486
- name: Run tests
492487
run: |
493488
cd validoopsie
494-
. .venv/bin/activate
489+
# empty pytest.ini to avoid pytest using narwhals configs
490+
touch pytest.ini
495491
touch tests/__init__.py
496492
touch tests/utils/__init__.py
497-
pytest tests
493+
uv run pytest tests
498494
timeout-minutes: 15
499495

500496
darts:

narwhals/_arrow/namespace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def len(self: Self) -> ArrowExpr:
6565
# coverage bug? this is definitely hit
6666
return self._expr( # pragma: no cover
6767
lambda df: [
68-
ArrowSeries._from_iterable(
68+
ArrowSeries.from_iterable(
6969
[len(df._native_frame)], name="len", context=self
7070
)
7171
],
@@ -79,7 +79,7 @@ def len(self: Self) -> ArrowExpr:
7979

8080
def lit(self: Self, value: Any, dtype: DType | None) -> ArrowExpr:
8181
def _lit_arrow_series(_: ArrowDataFrame) -> ArrowSeries:
82-
arrow_series = ArrowSeries._from_iterable(
82+
arrow_series = ArrowSeries.from_iterable(
8383
data=[value], name="literal", context=self
8484
)
8585
if dtype:

narwhals/_arrow/series.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Iterable
66
from typing import Iterator
77
from typing import Literal
8+
from typing import Mapping
89
from typing import Sequence
910
from typing import cast
1011
from typing import overload
@@ -32,6 +33,7 @@
3233
from narwhals.utils import Implementation
3334
from narwhals.utils import generate_temporary_column_name
3435
from narwhals.utils import import_dtypes_module
36+
from narwhals.utils import not_implemented
3537
from narwhals.utils import validate_backend_version
3638

3739
if TYPE_CHECKING:
@@ -139,12 +141,8 @@ def _from_native_series(
139141
)
140142

141143
@classmethod
142-
def _from_iterable(
143-
cls: type[Self],
144-
data: Iterable[Any],
145-
name: str,
146-
*,
147-
context: _FullContext,
144+
def from_iterable(
145+
cls, data: Iterable[Any], *, context: _FullContext, name: str = ""
148146
) -> Self:
149147
return cls(
150148
chunked_array([data]),
@@ -160,8 +158,8 @@ def _from_scalar(self, value: Any) -> Self:
160158

161159
@classmethod
162160
def from_numpy(cls, data: Into1DArray, /, *, context: _FullContext) -> Self:
163-
return cls._from_iterable(
164-
data if is_numpy_array_1d(data) else [data], name="", context=context
161+
return cls.from_iterable(
162+
data if is_numpy_array_1d(data) else [data], context=context
165163
)
166164

167165
def __narwhals_namespace__(self: Self) -> ArrowNamespace:
@@ -171,9 +169,6 @@ def __narwhals_namespace__(self: Self) -> ArrowNamespace:
171169
backend_version=self._backend_version, version=self._version
172170
)
173171

174-
def __len__(self: Self) -> int:
175-
return len(self.native)
176-
177172
def __eq__(self: Self, other: object) -> Self: # type: ignore[override]
178173
ser, other = extract_native(self, other)
179174
return self._from_native_series(pc.equal(ser, other)) # type: ignore[arg-type]
@@ -391,9 +386,6 @@ def __native_namespace__(self: Self) -> ModuleType:
391386
def name(self: Self) -> str:
392387
return self._name
393388

394-
def __narwhals_series__(self: Self) -> Self:
395-
return self
396-
397389
@overload
398390
def __getitem__(self: Self, idx: int) -> Any: ...
399391

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

571563
res = np.flatnonzero(self.native)
572-
return self._from_iterable(res, name=self.name, context=self)
564+
return self.from_iterable(res, name=self.name, context=self)
573565

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

755747
def replace_strict(
756-
self: Self, old: Sequence[Any], new: Sequence[Any], *, return_dtype: DType | None
748+
self: Self,
749+
old: Sequence[Any] | Mapping[Any, Any],
750+
new: Sequence[Any],
751+
*,
752+
return_dtype: DType | type[DType] | None,
757753
) -> Self:
758754
# https://stackoverflow.com/a/79111029/4451315
759755
idxs = pc.index_in(self.native, pa.array(old))
@@ -1217,3 +1213,5 @@ def list(self: Self) -> ArrowSeriesListNamespace:
12171213
@property
12181214
def struct(self: Self) -> ArrowSeriesStructNamespace:
12191215
return ArrowSeriesStructNamespace(self)
1216+
1217+
ewm_mean = not_implemented()

narwhals/_compliant/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from narwhals._compliant.typing import EagerSeriesT
2727
from narwhals._compliant.typing import IntoCompliantExpr
2828
from narwhals._compliant.typing import NativeFrameT_co
29+
from narwhals._compliant.typing import NativeSeriesT_co
2930

3031
__all__ = [
3132
"CompliantDataFrame",
@@ -54,4 +55,5 @@
5455
"LazyExpr",
5556
"LazySelectorNamespace",
5657
"NativeFrameT_co",
58+
"NativeSeriesT_co",
5759
]

narwhals/_compliant/expr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def quantile(
183183
) -> Self: ...
184184
def map_batches(
185185
self,
186-
function: Callable[[CompliantSeries], CompliantExpr[Any, Any]],
186+
function: Callable[[CompliantSeries[Any]], CompliantExpr[Any, Any]],
187187
return_dtype: DType | type[DType] | None,
188188
) -> Self: ...
189189

narwhals/_compliant/selectors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
]
6363

6464

65-
SeriesOrExprT = TypeVar("SeriesOrExprT", bound="CompliantSeries | NativeExpr")
66-
SeriesT = TypeVar("SeriesT", bound="CompliantSeries")
65+
SeriesOrExprT = TypeVar("SeriesOrExprT", bound="CompliantSeries[Any] | NativeExpr")
66+
SeriesT = TypeVar("SeriesT", bound="CompliantSeries[Any]")
6767
ExprT = TypeVar("ExprT", bound="NativeExpr")
6868
FrameT = TypeVar(
6969
"FrameT", bound="CompliantDataFrame[Any, Any, Any] | CompliantLazyFrame[Any, Any]"

0 commit comments

Comments
 (0)