From 69a89bc6c6da89789ca58391d1a7414ec5386f35 Mon Sep 17 00:00:00 2001 From: Shahar Naveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Tue, 27 Apr 2021 00:21:37 +0300 Subject: [PATCH] DOC: Fixed documentation for few files (#40903) Co-authored-by: ShaharNaveh <> --- ci/code_checks.sh | 3 ++ pandas/core/algorithms.py | 62 ++++++++++++++++++++++++--------------- pandas/core/indexers.py | 28 +++++++++++------- pandas/core/nanops.py | 4 +-- 4 files changed, 61 insertions(+), 36 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index a2a108924a0f2f..c178e9f7cecbee 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -110,10 +110,13 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then pytest -q --doctest-modules \ pandas/core/accessor.py \ pandas/core/aggregation.py \ + pandas/core/algorithms.py \ pandas/core/base.py \ pandas/core/construction.py \ pandas/core/frame.py \ pandas/core/generic.py \ + pandas/core/indexers.py \ + pandas/core/nanops.py \ pandas/core/series.py \ pandas/io/sql.py RET=$(($RET + $?)) ; echo $MSG "DONE" diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index c8389ae24f000e..16ec2bb5f253cc 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -375,46 +375,60 @@ def unique(values): >>> pd.unique(pd.Series([2] + [1] * 5)) array([2, 1]) - >>> pd.unique(pd.Series([pd.Timestamp('20160101'), - ... pd.Timestamp('20160101')])) + >>> pd.unique(pd.Series([pd.Timestamp("20160101"), pd.Timestamp("20160101")])) array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]') - >>> 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) - - >>> pd.unique(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'), - ... pd.Timestamp('20160101', tz='US/Eastern')])) + >>> pd.unique( + ... pd.Series( + ... [ + ... pd.Timestamp("20160101", tz="US/Eastern"), + ... pd.Timestamp("20160101", tz="US/Eastern"), + ... ] + ... ) + ... ) + + ['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'], - ... dtype='datetime64[ns, US/Eastern]', freq=None) + dtype='datetime64[ns, US/Eastern]', + freq=None) - >>> pd.unique(list('baabc')) + >>> pd.unique(list("baabc")) array(['b', 'a', 'c'], dtype=object) An unordered Categorical will return categories in the order of appearance. - >>> pd.unique(pd.Series(pd.Categorical(list('baabc')))) - [b, a, c] - Categories (3, object): [b, a, c] + >>> pd.unique(pd.Series(pd.Categorical(list("baabc")))) + ['b', 'a', 'c'] + Categories (3, object): ['a', 'b', 'c'] - >>> pd.unique(pd.Series(pd.Categorical(list('baabc'), - ... categories=list('abc')))) - [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): ['a', 'b', '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] + >>> pd.unique( + ... pd.Series( + ... pd.Categorical(list("baabc"), categories=list("abc"), ordered=True) + ... ) + ... ) + ['b', 'a', 'c'] + Categories (3, object): ['a' < 'b' < 'c'] An array of tuples - >>> pd.unique([('a', 'b'), ('b', 'a'), ('a', 'c'), ('b', 'a')]) + >>> pd.unique([("a", "b"), ("b", "a"), ("a", "c"), ("b", "a")]) array([('a', 'b'), ('b', 'a'), ('a', 'c')], dtype=object) """ values = _ensure_arraylike(values) diff --git a/pandas/core/indexers.py b/pandas/core/indexers.py index db28ad710989d6..aa780787d58b6d 100644 --- a/pandas/core/indexers.py +++ b/pandas/core/indexers.py @@ -209,16 +209,24 @@ 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.array([1, 2]), 3) # OK + + >>> validate_indices(np.array([1, -2]), 3) + Traceback (most recent call last): + ... + ValueError: negative dimensions are not allowed + + >>> validate_indices(np.array([1, 2, 3]), 3) + Traceback (most recent call last): + ... + IndexError: indices are out-of-bounds + + >>> validate_indices(np.array([-1, -1]), 0) # OK + + >>> validate_indices(np.array([0, 1]), 0) + Traceback (most recent call last): + ... + IndexError: indices are out-of-bounds """ if len(indices): min_idx = indices.min() diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 54588eafc3fa01..92618605e47cc5 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -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' @@ -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'