From 26db35dfdb545625ef6d54903f8a2d3e4d7dc787 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Sun, 19 May 2024 10:56:09 +0200 Subject: [PATCH 1/4] doc: fill in ser.is_in docstrings --- narwhals/series.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/narwhals/series.py b/narwhals/series.py index 9954f8906..0f3c1721d 100644 --- a/narwhals/series.py +++ b/narwhals/series.py @@ -440,6 +440,42 @@ def std(self, *, ddof: int = 1) -> Any: return self._series.std(ddof=ddof) def is_in(self, other: Any) -> Self: + """ + Check if elements of this Series are in the other Series. + + Arguments: + other: Series or sequence of primitive type. + + Examples: + >>> import pandas as pd + >>> import polars as pl + >>> import narwhals as nw + >>> s_pd = pd.Series([1, 2, 3]) + >>> s_pl = pl.Series([1, 2, 3]) + + We define a library agnostic function: + + >>> def func(s_any): + ... s = nw.from_native(s_any, series_only=True) + ... s = s.is_in(pl.Series([3, 2, 8])) + ... return nw.to_native(s) + + We can then pass either pandas or Polars to `func`: + + >>> func(s_pd) + 1 False + 2 True + 2 True + dtype: boolean + >>> func(s_pl) # doctest: +NORMALIZE_WHITESPACE + shape: (3,) + Series: '' [bool] + [ + false + true + true + ] + """ return self._from_series(self._series.is_in(self._extract_native(other))) def drop_nulls(self) -> Self: From 49ac3cbc2a3fb366df2f11783df86671949cdd68 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Sun, 19 May 2024 11:01:38 +0200 Subject: [PATCH 2/4] fix typo --- narwhals/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/narwhals/series.py b/narwhals/series.py index 0f3c1721d..f42e62e5b 100644 --- a/narwhals/series.py +++ b/narwhals/series.py @@ -463,8 +463,8 @@ def is_in(self, other: Any) -> Self: We can then pass either pandas or Polars to `func`: >>> func(s_pd) - 1 False - 2 True + 0 False + 1 True 2 True dtype: boolean >>> func(s_pl) # doctest: +NORMALIZE_WHITESPACE From a2dfd7103fb09552bc347c9c3d8159b250d8df77 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Tue, 21 May 2024 08:48:33 +0200 Subject: [PATCH 3/4] correct docstring --- narwhals/series.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/narwhals/series.py b/narwhals/series.py index f42e62e5b..9e12bcae1 100644 --- a/narwhals/series.py +++ b/narwhals/series.py @@ -441,10 +441,10 @@ def std(self, *, ddof: int = 1) -> Any: def is_in(self, other: Any) -> Self: """ - Check if elements of this Series are in the other Series. + Check if elements of this sequence are present in the other Series. Arguments: - other: Series or sequence of primitive type. + other: Sequence of primitive type. Examples: >>> import pandas as pd @@ -457,7 +457,7 @@ def is_in(self, other: Any) -> Self: >>> def func(s_any): ... s = nw.from_native(s_any, series_only=True) - ... s = s.is_in(pl.Series([3, 2, 8])) + ... s = s.is_in([3, 2, 8]) ... return nw.to_native(s) We can then pass either pandas or Polars to `func`: From 53810051a95c576825ac66530b72cdf87695d73d Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Tue, 21 May 2024 15:48:58 +0200 Subject: [PATCH 4/4] correct the summary --- narwhals/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/narwhals/series.py b/narwhals/series.py index 9e12bcae1..a51089cf2 100644 --- a/narwhals/series.py +++ b/narwhals/series.py @@ -441,7 +441,7 @@ def std(self, *, ddof: int = 1) -> Any: def is_in(self, other: Any) -> Self: """ - Check if elements of this sequence are present in the other Series. + Check if the elements of this Series are in the other sequence. Arguments: other: Sequence of primitive type.