-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Fixed examples in pandas/core/arrays/ #33179
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
DOC: Fixed examples in pandas/core/arrays/ #33179
Conversation
pandas/core/arrays/categorical.py
Outdated
Categories (3, object): [a < b < c] | ||
|
||
|
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.
do we need two lines here or just one?
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.
I think one.
Besides "See also" header, should come before the "Examples" header.
Ill fix that
pandas/core/arrays/datetimelike.py
Outdated
@@ -181,7 +181,7 @@ def _unbox_scalar(self, value: Union[Period, Timestamp, Timedelta, NaTType]) -> | |||
|
|||
Examples | |||
-------- | |||
>>> self._unbox_scalar(Timedelta('10s')) # DOCTEST: +SKIP | |||
>>> _unbox_scalar(Timedelta('10s')) # doctest: +SKIP |
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.
i think this makes less sense without the self
, but skipping is OK
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.
I agree, let's keep the self
here (this is an internal docstring and not a runnable example anyway)
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.
I was trying to see if this will run without the "self", forgot to revert it.
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.
Thanks for working on those!
pandas/core/arrays/categorical.py
Outdated
[b, a, c] | ||
Categories (3, object): [b, a, c] | ||
[b, a, a, b, c] | ||
Categories (3, object): [a, b, c] |
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.
I think there are missing unique()
calls here (and then the output should be correct), since we are in the unique docstring
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.
Good catch!
I got into a tunnel vision of just correcting the output, I guess I didn't even looked at what is the docstring I'm editing
pandas/core/arrays/categorical.py
Outdated
>>> s.cat.add_categories(['d','e']) | ||
Index(['a', 'b', 'c'], dtype='object') | ||
|
||
>>> s.cat.categories = list("bcd") |
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.
I personally think we should remove this example ... (seems bad practice to me to modify the categorical like this in place)
pandas/core/arrays/categorical.py
Outdated
3 NaN | ||
dtype: category | ||
Categories (2, object): [b, c] | ||
|
||
>>> s.cat.remove_unused_categories() |
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.
Can you assign the above one with add_categories
to eg s2
and use that here? (so the remove_unused_categories
actually has an effect)
pandas/core/arrays/datetimelike.py
Outdated
@@ -181,7 +181,7 @@ def _unbox_scalar(self, value: Union[Period, Timestamp, Timedelta, NaTType]) -> | |||
|
|||
Examples | |||
-------- | |||
>>> self._unbox_scalar(Timedelta('10s')) # DOCTEST: +SKIP | |||
>>> _unbox_scalar(Timedelta('10s')) # doctest: +SKIP |
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.
I agree, let's keep the self
here (this is an internal docstring and not a runnable example anyway)
3 3.0 | ||
4 NaN | ||
5 NaN | ||
dtype: float64 |
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.
I would leave this out, since you already show the output of s
below after setting the index, and it is the Series with the multi-index that is relevant for the rest of the example
Co-Authored-By: Joris Van den Bossche <[email protected]>
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.
checks are failing
Co-Authored-By: Joris Van den Bossche <[email protected]>
LGTM |
Thanks @MomIsBestFriend |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff