nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: narwhals-dev/narwhals
Pull request #137 (2024-05-11 07:02:24)

Add series eq/ne


Patch:
diff --git a/narwhals/series.py b/narwhals/series.py
index 026efca3..f82aa1a6 100644
--- a/narwhals/series.py
+++ b/narwhals/series.py
@@ -549,6 +549,12 @@ class Series:
     def to_pandas(self) -> Any:
         return self._series.to_pandas()
 
+    def __eq__(self, other: object) -> Series:  # type: ignore[override]
+        return self._from_series(self._series.__eq__(self._extract_native(other)))
+
+    def __ne__(self, other: object) -> Series:  # type: ignore[override]
+        return self._from_series(self._series.__ne__(self._extract_native(other)))
+
     def __gt__(self, other: Any) -> Series:
         return self._from_series(self._series.__gt__(self._extract_native(other)))
 


Test patch:
diff --git a/tests/series/__init__.py b/tests/series/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/tests/series/eq_ne_test.py b/tests/series/eq_ne_test.py
new file mode 100644
index 00000000..fe1df038
--- /dev/null
+++ b/tests/series/eq_ne_test.py
@@ -0,0 +1,16 @@
+from typing import Any
+
+import pandas as pd
+import polars as pl
+import pytest
+
+import narwhals as nw
+
+data = [1, 2, 3]
+
+
+@pytest.mark.parametrize("constructor", [pd.Series, pl.Series])
+def test_eq_ne(constructor: Any) -> None:
+    s = nw.from_native(constructor(data), series_only=True)
+    assert (s == 1).to_numpy().tolist() == [True, False, False]
+    assert (s != 1).to_numpy().tolist() == [False, True, True]