Repository: narwhals-dev/narwhals
Pull request #548 (2024-07-18 15:24:53)

feat: arrow series `zip_with`
## What type of PR is this? (check all applicable)

- [ ] 💾 Refactor
- [x] ✨ Feature
- [ ] 🐛 Bug Fix
- [ ] 🔧 Optimization
- [ ] 📝 Documentation
- [ ] ✅ Test
- [ ] 🐳 Other

## Related issues 

- Related issue #372 

## Checklist

- [x] Code follows style guide (ruff)
- [x] Tests added 
- [x] Documented the changes

## If you have comments or can explain your changes, please do so below.

A tiny one :) 



Patch:
diff --git a/narwhals/_arrow/series.py b/narwhals/_arrow/series.py
index f46d6935..e02b89d3 100644
--- a/narwhals/_arrow/series.py
+++ b/narwhals/_arrow/series.py
@@ -283,6 +283,17 @@ class ArrowSeries:
             return self._native_series[0].as_py()
         return self._native_series[index].as_py()
 
+    def zip_with(self: Self, mask: Self, other: Self) -> Self:
+        pc = get_pyarrow_compute()
+
+        return self._from_native_series(
+            pc.replace_with_mask(
+                self._native_series.combine_chunks(),
+                pc.invert(mask._native_series.combine_chunks()),
+                other._native_series.combine_chunks(),
+            )
+        )
+
     @property
     def shape(self) -> tuple[int]:
         return (len(self._native_series),)
diff --git a/narwhals/series.py b/narwhals/series.py
index 787275d3..41664540 100644
--- a/narwhals/series.py
+++ b/narwhals/series.py
@@ -1729,9 +1729,16 @@ class Series:
             quantile=quantile, interpolation=interpolation
         )
 
-    def zip_with(self, mask: Any, other: Any) -> Self:
+    def zip_with(self: Self, mask: Self, other: Self) -> Self:
         """
-        Take values from self or other based on the given mask. Where mask evaluates true, take values from self. Where mask evaluates false, take values from other.
+        Take values from self or other based on the given mask.
+
+        Where mask evaluates true, take values from self. Where mask evaluates false,
+        take values from other.
+
+        Arguments:
+            mask: Boolean Series
+            other: Series of same type.
 
         Examples:
             >>> import narwhals as nw
diff --git a/utils/check_backend_completeness.py b/utils/check_backend_completeness.py
index f2c4f9c2..827eae5c 100644
--- a/utils/check_backend_completeness.py
+++ b/utils/check_backend_completeness.py
@@ -36,7 +36,6 @@ MISSING = [
     "Series.to_pandas",
     "Series.unique",
     "Series.value_counts",
-    "Series.zip_with",
 ]
 
 


Test patch:
diff --git a/tests/series_only/test_common.py b/tests/series_only/test_common.py
index d8e6a549..5f53c6ad 100644
--- a/tests/series_only/test_common.py
+++ b/tests/series_only/test_common.py
@@ -233,10 +233,7 @@ def test_quantile(
     assert result == expected
 
 
-def test_zip_with(request: Any, constructor_series: Any) -> None:
-    if "pyarrow_series" in str(constructor_series):
-        request.applymarker(pytest.mark.xfail)
-
+def test_zip_with(constructor_series: Any) -> None:
     series1 = nw.from_native(constructor_series(data), series_only=True)
     series2 = nw.from_native(constructor_series(data_dups), series_only=True)
     mask = nw.from_native(constructor_series([True, False, True]), series_only=True)