Skip to content

Commit

Permalink
Merge pull request #137 from narwhals-dev/eq-ne
Browse files Browse the repository at this point in the history
Add series eq/ne
  • Loading branch information
MarcoGorelli authored May 11, 2024
2 parents d0c3715 + 288c40a commit 8f488ee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions narwhals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,12 @@ def to_numpy(self) -> Any:
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)))

Expand Down
Empty file added tests/series/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions tests/series/eq_ne_test.py
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 8f488ee

Please sign in to comment.