Skip to content

Commit 12561ed

Browse files
authored
Create pandas.Series.__invert__.rst
1 parent bbcf86f commit 12561ed

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.. currentmodule:: pandas
2+
3+
pandas.Series.__invert__
4+
========================
5+
6+
Elementwise invert (``~``) for :class:`pandas.Series`.
7+
8+
**Signature**
9+
``Series.__invert__(self) -> Series``
10+
11+
**Summary**
12+
For boolean and nullable-boolean dtypes, ``~s`` toggles the mask
13+
(``True`` ↔ ``False``) and propagates ``pd.NA``. For integer dtypes,
14+
``~`` performs bitwise invert as in Python.
15+
16+
**Examples**
17+
18+
Boolean / nullable boolean::
19+
20+
>>> s = pd.Series([True, pd.NA, False], dtype="boolean")
21+
>>> ~s
22+
0 False
23+
1 <NA>
24+
2 True
25+
dtype: boolean
26+
27+
Integer vs boolean::
28+
29+
>>> s_int = pd.Series([0, 1, 2], dtype="int64")
30+
>>> ~s_int
31+
0 -1
32+
1 -2
33+
2 -3
34+
dtype: int64
35+
36+
Arrow-backed boolean (if pyarrow installed)::
37+
38+
>>> s_arrow = pd.Series([True, pd.NA, False], dtype="boolean[pyarrow]")
39+
>>> ~s_arrow
40+
0 False
41+
1 <NA>
42+
2 True
43+
dtype: boolean[pyarrow]
44+
45+
**Notes**
46+
* In Python’s stdlib, :func:`operator.__invert__` is bitwise invert on integers.
47+
In pandas, ``~`` on boolean arrays is elementwise invert.
48+
* See also :ref:`user_guide.boolean_indexing`.

0 commit comments

Comments
 (0)