Skip to content

DOC: Fixed documentation for few files #40903

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

Merged
merged 17 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then

# Individual files

MSG='Doctests algorithms.py' ; echo $MSG
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these be combined? e.g. 1 for files, 1 for directories

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will open a separate PR for that.

pytest -q --doctest-modules pandas/core/algorithms.py
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests accessor.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/accessor.py
RET=$(($RET + $?)) ; echo $MSG "DONE"
Expand All @@ -162,6 +166,14 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
pytest -q --doctest-modules pandas/core/generic.py
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests indexers.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/indexers.py
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests nanops.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/nanops.py
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests series.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/series.py
RET=$(($RET + $?)) ; echo $MSG "DONE"
Expand Down
20 changes: 11 additions & 9 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,15 @@ def unique(values):

>>> pd.unique(pd.Series([pd.Timestamp('20160101', tz='US/Eastern'),
... pd.Timestamp('20160101', tz='US/Eastern')]))
array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')],
dtype=object)
<DatetimeArray>
['2016-01-01 00:00:00-05:00']
Length: 1, dtype: datetime64[ns, US/Eastern]

>>> pd.unique(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
... pd.Timestamp('20160101', tz='US/Eastern')]))
DatetimeIndex(['2016-01-01 00:00:00-05:00'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format here looks a bit odd?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the "Black" formatting.

I personally think it's easier on the eyes, but that's not a deal breaker for me.

Can revert if you think it's best to leave it as it was before

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if this was misleading, I was referring to the lines you haven‘t touched, they look out of sync now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't managed to get the output lines to follow the "black" formatting styles.

What I could do is to make the output to appear in a single line, instead of multiple by using \. i.e

def foo():
    """
    Examples
    --------------
    >> foo()
    Line1 \
Line 2 \
Line 3 \
    """

Will result in the docs as:

>>> foo()
Line 1 Line 2 Line 3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me

... dtype='datetime64[ns, US/Eastern]', freq=None)
dtype='datetime64[ns, US/Eastern]',
freq=None)

>>> pd.unique(list('baabc'))
array(['b', 'a', 'c'], dtype=object)
Expand All @@ -396,21 +398,21 @@ def unique(values):
order of appearance.

>>> pd.unique(pd.Series(pd.Categorical(list('baabc'))))
[b, a, c]
Categories (3, object): [b, a, c]
['b', 'a', 'c']
Categories (3, object): ['b', 'a', 'c']

>>> pd.unique(pd.Series(pd.Categorical(list('baabc'),
... categories=list('abc'))))
[b, a, c]
Categories (3, object): [b, a, c]
['b', 'a', 'c']
Categories (3, object): ['b', 'a', 'c']

An ordered Categorical preserves the category ordering.

>>> pd.unique(pd.Series(pd.Categorical(list('baabc'),
... categories=list('abc'),
... ordered=True)))
[b, a, c]
Categories (3, object): [a < b < c]
['b', 'a', 'c']
Categories (3, object): ['a' < 'b' < 'c']

An array of tuples

Expand Down
25 changes: 15 additions & 10 deletions pandas/core/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,21 @@ def validate_indices(indices: np.ndarray, n: int) -> None:

Examples
--------
>>> validate_indices([1, 2], 3)
# OK
>>> validate_indices([1, -2], 3)
ValueError
>>> validate_indices([1, 2, 3], 3)
IndexError
>>> validate_indices([-1, -1], 0)
# OK
>>> validate_indices([0, 1], 0)
IndexError
>>> validate_indices(np.ndarray([1, 2]), 3) # OK

>>> validate_indices(np.ndarray([1, -2]), 3)
Traceback (most recent call last):
...
ValueError: negative dimensions are not allowed

>>> validate_indices(np.ndarray([1, 2, 3]), 3) # OK

>>> validate_indices(np.ndarray([-1, -1]), 0)
Traceback (most recent call last):
...
ValueError: negative dimensions are not allowed

>>> validate_indices(np.ndarray([0, 1]), 0) # OK
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs in master ATM says it should raise an IndexError, but it does not.
Would be glad if someone will take a look here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using np.ndarray instead of np.array? The latter one raises

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using np.ndarray instead of np.array? The latter one raises

I complety missed it, I have pushed a fix for it in 857c110

"""
if len(indices):
min_idx = indices.min()
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ def nanargmax(
[ 6., 7., nan],
[ 9., 10., nan]])
>>> nanops.nanargmax(arr, axis=1)
array([2, 2, 1, 1], dtype=int64)
array([2, 2, 1, 1])
"""
values, mask, _, _, _ = _get_values(values, True, fill_value_typ="-inf", mask=mask)
# error: Need type annotation for 'result'
Expand Down Expand Up @@ -1102,7 +1102,7 @@ def nanargmin(
[nan, 7., 8.],
[nan, 10., 11.]])
>>> nanops.nanargmin(arr, axis=1)
array([0, 0, 1, 1], dtype=int64)
array([0, 0, 1, 1])
"""
values, mask, _, _, _ = _get_values(values, True, fill_value_typ="+inf", mask=mask)
# error: Need type annotation for 'result'
Expand Down