-
-
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
base: main
Are you sure you want to change the base?
Changes from all commits
12561ed
e34048d
10ba2d2
ebe43ac
5eb92c6
b147018
2428f9d
c9fb49b
fc0415e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -781,3 +781,41 @@ def make_flex_doc(op_name: str, typ: str) -> str: | |
| B True False | ||
| C True False | ||
| """ | ||
|
|
||
| # --- add at bottom of pandas/core/ops/docstrings.py --- | ||
|
|
||
| _doc_series_invert = """ | ||
| Bitwise NOT (``~``). | ||
|
|
||
| For boolean dtype, behaves as logical NOT. Missing values (``NA``) propagate. | ||
| For integer dtypes, performs bitwise inversion (two's complement) elementwise. | ||
|
|
||
| Returns | ||
| ------- | ||
| Series | ||
| Elementwise result with the same index and name. | ||
|
|
||
| Notes | ||
| ----- | ||
| On ``boolean[pyarrow]`` dtype, ``NA`` values also propagate under ``~``. | ||
|
|
||
| See Also | ||
| -------- | ||
| Series.__and__, Series.__or__, Series.__xor__ | ||
|
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. Can you separate out to one line each, with a short description. See other docstrings in this file for examples. |
||
|
|
||
| Examples | ||
| -------- | ||
| >>> s = pd.Series([True, False, pd.NA], dtype="boolean") | ||
| >>> ~s | ||
| 0 False | ||
| 1 True | ||
| 2 <NA> | ||
| dtype: boolean | ||
|
|
||
| >>> s = pd.Series([1, 2, -3], dtype="Int32") | ||
| >>> ~s | ||
| 0 -2 | ||
| 1 -3 | ||
| 2 2 | ||
| dtype: Int32 | ||
| """ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7338,3 +7338,7 @@ def cumsum(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: | |
| @doc(make_doc("cumprod", 1)) | ||
| def cumprod(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: | ||
| return NDFrame.cumprod(self, axis, skipna, *args, **kwargs) | ||
|
|
||
| # at bottom of pandas/core/series.py (after class Series ...) | ||
| from pandas.core.ops.docstrings import _doc_series_invert | ||
| Series.__invert__.__doc__ = _doc_series_invert | ||
|
Comment on lines
+7342
to
+7344
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. I think we can instead add the following to def __invert__(self) -> Self:
return super().__invert__()Then we can add the docstring there. But I would like a 2nd opinion here, cc @mroeschke.
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. Agreed. It's best to keep docstring with the function definitions |
||
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.
~is already mentioned in the paragraph above; I think this can be removed.