Repository: narwhals-dev/narwhals (python)

Issue:
bug: `ArrowSeries.scatter` raises out of bound error
pyarrow backed series raises an out of bound error in scatter if `indices`:

- is not 0
- are not full length of the series

Repro:

```py
import narwhals as nw
import pyarrow as pa

tbl = pa.table({"a": [1, 2, 3], "b": [142, 124, 132]})
frame = nw.from_native(tbl, eager_only=True)
ser = frame["a"]

try:
    result = ser.scatter(1, 999)
except Exception as exc:
    print(exc)


try:
    result = ser.scatter([0, 2], [999, 888])
except Exception as exc:
    print(exc)
```

> Index 1 out of bounds
> Index 2 out of bounds



Pull request:
fix: `scatter` was raising unnecessarily for pyarrow
closes #2862

<!--
# Thanks for contributing a pull request! 
## Please make sure you see our contribution guidelines: https://github.com/narwhals-dev/narwhals/blob/main/CONTRIBUTING.md
-->

## What type of PR is this? (check all applicable)

- [ ] 💾 Refactor
- [ ] ✨ Feature
- [ ] 🐛 Bug Fix
- [ ] 🔧 Optimization
- [ ] 📝 Documentation
- [ ] ✅ Test
- [ ] 🐳 Other

## Related issues

- Related issue #\<issue number\>
- Closes #\<issue number\>

## Checklist

- [ ] Code follows style guide (ruff)
- [ ] Tests added
- [ ] Documented the changes

## If you have comments or can explain your changes, please do so below


Patch:
diff --git a/narwhals/_arrow/series.py b/narwhals/_arrow/series.py
index e22d20fe..7aad2638 100644
--- a/narwhals/_arrow/series.py
+++ b/narwhals/_arrow/series.py
@@ -467,9 +467,7 @@ class ArrowSeries(EagerSeries["ChunkedArrayAny"]):
         # - Missing `replacements` type
         # - Missing return type
         pc_replace_with_mask: Incomplete = pc.replace_with_mask
-        return self._with_native(
-            pc_replace_with_mask(self.native, mask, values_native.take(indices_native))
-        )
+        return self._with_native(pc_replace_with_mask(self.native, mask, values_native))
 
     def to_list(self) -> list[Any]:
         return self.native.to_pylist()


Test patch:
diff --git a/tests/series_only/scatter_test.py b/tests/series_only/scatter_test.py
index 2e5cbaa1..65b8c3d9 100644
--- a/tests/series_only/scatter_test.py
+++ b/tests/series_only/scatter_test.py
@@ -61,3 +61,19 @@ def test_scatter_unordered_indices(constructor_eager: ConstructorEager) -> None:
     df = nw.from_native(constructor_eager(data))
     result = df["a"].scatter(indices, df["a"])
     assert_equal_data({"a": result}, {"a": [10, 12, 5, 6, 2, 9, 16]})
+
+
+def test_scatter_2862(constructor_eager: ConstructorEager) -> None:
+    df = nw.from_native(
+        constructor_eager({"a": [1, 2, 3], "b": [142, 124, 132]}), eager_only=True
+    )
+    ser = df["a"]
+    result = ser.scatter(1, 999)
+    expected = {"a": [1, 999, 3]}
+    assert_equal_data({"a": result}, expected)
+    result = ser.scatter([0, 2], [999, 888])
+    expected = {"a": [999, 2, 888]}
+    assert_equal_data({"a": result}, expected)
+    result = ser.scatter([2, 0], [999, 888])
+    expected = {"a": [888, 2, 999]}
+    assert_equal_data({"a": result}, expected)