-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
DOC: Add docs for Series.__invert__ (~); add cross-link from Boolean indexing #62641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rlawnsrl123
wants to merge
9
commits into
pandas-dev:main
Choose a base branch
from
rlawnsrl123:doc/series-invert
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
12561ed
Create pandas.Series.__invert__.rst
rlawnsrl123 e34048d
DOC: add unary operator section; link Series.__invert__
rlawnsrl123 10ba2d2
DOC: Add docs for Series.__invert__ (~); add cross-link from Boolean …
rlawnsrl123 ebe43ac
Update pandas.Series.__invert__.rst
rlawnsrl123 5eb92c6
Update pandas.Series.__invert__.rst
rlawnsrl123 b147018
DOC : switch series.rst entry to autosummary
rlawnsrl123 2428f9d
DOC: remove manual API page for Series.__invert__ (moved to docstring)
rlawnsrl123 c9fb49b
DOC: add Series.__invert__ docstring template
rlawnsrl123 fc0415e
DOC: bind Series.__invert__ to new docstring
rlawnsrl123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| .. currentmodule:: pandas | ||
|
|
||
| pandas.Series.__invert__ | ||
| ======================== | ||
|
|
||
| Elementwise invert (``~``) for :class:`pandas.Series`. | ||
|
|
||
| **Signature** | ||
|
|
||
| ``Series.__invert__(self) -> Series`` | ||
|
|
||
| **Summary** | ||
|
|
||
| For boolean and nullable-boolean dtypes, ``~s`` toggles the mask | ||
| (``True`` ↔ ``False``) and propagates ``pd.NA``. For integer dtypes, | ||
| ``~`` performs bitwise invert as in Python. | ||
|
|
||
| .. seealso:: | ||
| :ref:`Boolean indexing <indexing.boolean>` | ||
|
|
||
| **Examples** | ||
|
|
||
| Boolean / nullable boolean:: | ||
|
|
||
| >>> s = pd.Series([True, pd.NA, False], dtype="boolean") | ||
| >>> ~s | ||
| 0 False | ||
| 1 <NA> | ||
| 2 True | ||
| dtype: boolean | ||
|
|
||
| Integer vs boolean:: | ||
|
|
||
| >>> s_int = pd.Series([0, 1, 2], dtype="int64") | ||
| >>> ~s_int | ||
| 0 -1 | ||
| 1 -2 | ||
| 2 -3 | ||
| dtype: int64 | ||
|
|
||
| Arrow-backed boolean (if pyarrow installed):: | ||
|
|
||
| >>> s_arrow = pd.Series([True, pd.NA, False], dtype="boolean[pyarrow]") | ||
| >>> ~s_arrow | ||
| 0 False | ||
| 1 <NA> | ||
| 2 True | ||
| dtype: boolean[pyarrow] | ||
|
|
||
| **Notes** | ||
|
|
||
| - In Python’s stdlib, :func:`operator.__invert__` is bitwise invert on integers. | ||
| In pandas, ``~`` on boolean arrays is elementwise invert. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,6 +107,14 @@ Binary operator functions | |
| Series.product | ||
| Series.dot | ||
|
|
||
| Unary operator functions | ||
| ------------------------ | ||
| .. toctree:: | ||
| :maxdepth: 1 | ||
|
|
||
| api/pandas.Series.__invert__ | ||
|
||
|
|
||
|
|
||
| Function application, GroupBy & window | ||
| -------------------------------------- | ||
| .. autosummary:: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -811,6 +811,10 @@ evaluate an expression such as ``df['A'] > 2 & df['B'] < 3`` as | |
| ``df['A'] > (2 & df['B']) < 3``, while the desired evaluation order is | ||
| ``(df['A'] > 2) & (df['B'] < 3)``. | ||
|
|
||
| For toggling boolean masks with the ``~`` operator, see | ||
| :meth:`pandas.Series.__invert__`. | ||
|
Comment on lines
+814
to
+815
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
||
| Using a boolean vector to index a Series works exactly as in a NumPy ndarray: | ||
|
|
||
| .. ipython:: python | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the request above, this file can be removed. Add anything necessary to the docstring of
__invert__instead.