Skip to content

Commit

Permalink
python is_in docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 9, 2021
1 parent 2f24dc1 commit 4c0d7b3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
12 changes: 12 additions & 0 deletions polars/polars-core/src/chunked_array/ops/is_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ where
}
}
}
.map(|mut ca| {
ca.rename(self.name());
ca
})
}
}
impl IsIn for Utf8Chunked {
Expand Down Expand Up @@ -143,6 +147,10 @@ impl IsIn for Utf8Chunked {
.into(),
)),
}
.map(|mut ca| {
ca.rename(self.name());
ca
})
}
}

Expand Down Expand Up @@ -172,6 +180,10 @@ impl IsIn for BooleanChunked {
.into(),
)),
}
.map(|mut ca| {
ca.rename(self.name());
ca
})
}
}

Expand Down
20 changes: 20 additions & 0 deletions py-polars/polars/internals/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,26 @@ def is_in(self, other: Union["Expr", tp.List[Any]]) -> "Expr":
Returns
-------
Expr that evaluates to a Boolean Series.
Examples
--------
>>> df = pl.DataFrame(
... {"sets": [[1, 2, 3], [1, 2], [9, 10]], "optional_members": [1, 2, 3]}
... )
>>> df.select([pl.col("optional_members").is_in("sets").alias("contains")])
shape: (3, 1)
┌──────────┐
│ contains │
│ --- │
│ bool │
╞══════════╡
│ true │
├╌╌╌╌╌╌╌╌╌╌┤
│ true │
├╌╌╌╌╌╌╌╌╌╌┤
│ false │
└──────────┘
"""
if isinstance(other, list):
other = pli.lit(pli.Series(other))
Expand Down
28 changes: 28 additions & 0 deletions py-polars/polars/internals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,34 @@ def is_in(self, other: Union["Series", tp.List]) -> "Series":
false
]
>>> # check if some values are a member of sublists
>>> sets = pl.Series("sets", [[1, 2, 3], [1, 2], [9, 10]])
>>> optional_members = pl.Series("optional_members", [1, 2, 3])
>>> print(sets)
shape: (3,)
Series: 'sets' [list]
[
[1, 2, 3]
[1, 2]
[9, 10]
]
>>> print(optional_members)
shape: (3,)
Series: 'optional_members' [i64]
[
1
2
3
]
>>> optional_members.is_in(sets)
shape: (3,)
Series: 'optional_members' [bool]
[
true
true
false
]
"""
if isinstance(other, list):
other = Series("", other)
Expand Down

0 comments on commit 4c0d7b3

Please sign in to comment.