Skip to content

Commit 471f7e7

Browse files
ShaharNavehyeshsurya
authored andcommitted
DOC: Fixed documentation for few files (pandas-dev#40903)
Co-authored-by: ShaharNaveh <>
1 parent 39c585e commit 471f7e7

File tree

4 files changed

+61
-36
lines changed

4 files changed

+61
-36
lines changed

ci/code_checks.sh

+3
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,13 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
110110
pytest -q --doctest-modules \
111111
pandas/core/accessor.py \
112112
pandas/core/aggregation.py \
113+
pandas/core/algorithms.py \
113114
pandas/core/base.py \
114115
pandas/core/construction.py \
115116
pandas/core/frame.py \
116117
pandas/core/generic.py \
118+
pandas/core/indexers.py \
119+
pandas/core/nanops.py \
117120
pandas/core/series.py \
118121
pandas/io/sql.py
119122
RET=$(($RET + $?)) ; echo $MSG "DONE"

pandas/core/algorithms.py

+38-24
Original file line numberDiff line numberDiff line change
@@ -375,46 +375,60 @@ def unique(values):
375375
>>> pd.unique(pd.Series([2] + [1] * 5))
376376
array([2, 1])
377377
378-
>>> pd.unique(pd.Series([pd.Timestamp('20160101'),
379-
... pd.Timestamp('20160101')]))
378+
>>> pd.unique(pd.Series([pd.Timestamp("20160101"), pd.Timestamp("20160101")]))
380379
array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]')
381380
382-
>>> pd.unique(pd.Series([pd.Timestamp('20160101', tz='US/Eastern'),
383-
... pd.Timestamp('20160101', tz='US/Eastern')]))
384-
array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')],
385-
dtype=object)
386-
387-
>>> pd.unique(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
388-
... pd.Timestamp('20160101', tz='US/Eastern')]))
381+
>>> pd.unique(
382+
... pd.Series(
383+
... [
384+
... pd.Timestamp("20160101", tz="US/Eastern"),
385+
... pd.Timestamp("20160101", tz="US/Eastern"),
386+
... ]
387+
... )
388+
... )
389+
<DatetimeArray>
390+
['2016-01-01 00:00:00-05:00']
391+
Length: 1, dtype: datetime64[ns, US/Eastern]
392+
393+
>>> pd.unique(
394+
... pd.Index(
395+
... [
396+
... pd.Timestamp("20160101", tz="US/Eastern"),
397+
... pd.Timestamp("20160101", tz="US/Eastern"),
398+
... ]
399+
... )
400+
... )
389401
DatetimeIndex(['2016-01-01 00:00:00-05:00'],
390-
... dtype='datetime64[ns, US/Eastern]', freq=None)
402+
dtype='datetime64[ns, US/Eastern]',
403+
freq=None)
391404
392-
>>> pd.unique(list('baabc'))
405+
>>> pd.unique(list("baabc"))
393406
array(['b', 'a', 'c'], dtype=object)
394407
395408
An unordered Categorical will return categories in the
396409
order of appearance.
397410
398-
>>> pd.unique(pd.Series(pd.Categorical(list('baabc'))))
399-
[b, a, c]
400-
Categories (3, object): [b, a, c]
411+
>>> pd.unique(pd.Series(pd.Categorical(list("baabc"))))
412+
['b', 'a', 'c']
413+
Categories (3, object): ['a', 'b', 'c']
401414
402-
>>> pd.unique(pd.Series(pd.Categorical(list('baabc'),
403-
... categories=list('abc'))))
404-
[b, a, c]
405-
Categories (3, object): [b, a, c]
415+
>>> pd.unique(pd.Series(pd.Categorical(list("baabc"), categories=list("abc"))))
416+
['b', 'a', 'c']
417+
Categories (3, object): ['a', 'b', 'c']
406418
407419
An ordered Categorical preserves the category ordering.
408420
409-
>>> pd.unique(pd.Series(pd.Categorical(list('baabc'),
410-
... categories=list('abc'),
411-
... ordered=True)))
412-
[b, a, c]
413-
Categories (3, object): [a < b < c]
421+
>>> pd.unique(
422+
... pd.Series(
423+
... pd.Categorical(list("baabc"), categories=list("abc"), ordered=True)
424+
... )
425+
... )
426+
['b', 'a', 'c']
427+
Categories (3, object): ['a' < 'b' < 'c']
414428
415429
An array of tuples
416430
417-
>>> pd.unique([('a', 'b'), ('b', 'a'), ('a', 'c'), ('b', 'a')])
431+
>>> pd.unique([("a", "b"), ("b", "a"), ("a", "c"), ("b", "a")])
418432
array([('a', 'b'), ('b', 'a'), ('a', 'c')], dtype=object)
419433
"""
420434
values = _ensure_arraylike(values)

pandas/core/indexers.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,24 @@ def validate_indices(indices: np.ndarray, n: int) -> None:
209209
210210
Examples
211211
--------
212-
>>> validate_indices([1, 2], 3)
213-
# OK
214-
>>> validate_indices([1, -2], 3)
215-
ValueError
216-
>>> validate_indices([1, 2, 3], 3)
217-
IndexError
218-
>>> validate_indices([-1, -1], 0)
219-
# OK
220-
>>> validate_indices([0, 1], 0)
221-
IndexError
212+
>>> validate_indices(np.array([1, 2]), 3) # OK
213+
214+
>>> validate_indices(np.array([1, -2]), 3)
215+
Traceback (most recent call last):
216+
...
217+
ValueError: negative dimensions are not allowed
218+
219+
>>> validate_indices(np.array([1, 2, 3]), 3)
220+
Traceback (most recent call last):
221+
...
222+
IndexError: indices are out-of-bounds
223+
224+
>>> validate_indices(np.array([-1, -1]), 0) # OK
225+
226+
>>> validate_indices(np.array([0, 1]), 0)
227+
Traceback (most recent call last):
228+
...
229+
IndexError: indices are out-of-bounds
222230
"""
223231
if len(indices):
224232
min_idx = indices.min()

pandas/core/nanops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ def nanargmax(
10561056
[ 6., 7., nan],
10571057
[ 9., 10., nan]])
10581058
>>> nanops.nanargmax(arr, axis=1)
1059-
array([2, 2, 1, 1], dtype=int64)
1059+
array([2, 2, 1, 1])
10601060
"""
10611061
values, mask, _, _, _ = _get_values(values, True, fill_value_typ="-inf", mask=mask)
10621062
# error: Need type annotation for 'result'
@@ -1102,7 +1102,7 @@ def nanargmin(
11021102
[nan, 7., 8.],
11031103
[nan, 10., 11.]])
11041104
>>> nanops.nanargmin(arr, axis=1)
1105-
array([0, 0, 1, 1], dtype=int64)
1105+
array([0, 0, 1, 1])
11061106
"""
11071107
values, mask, _, _, _ = _get_values(values, True, fill_value_typ="+inf", mask=mask)
11081108
# error: Need type annotation for 'result'

0 commit comments

Comments
 (0)