Skip to content

Commit 43ceef4

Browse files
DeaMariaLeonim-vinicius
authored and
im-vinicius
committed
DOC: Fixing EX01 - Added examples (pandas-dev#53352)
* DOC Added Index examples Index.drop, identical, insert DOC: Fixing EX01 - Added examples (pandas-dev#53336) * Examples * Changed Index.copy * Corrected Float32Dtype & Float64Dtype Added is_, take, putmask, unique * Modified Index.is_ and take examples
1 parent 47a19ee commit 43ceef4

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

ci/code_checks.sh

-7
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
254254
pandas.util.hash_pandas_object \
255255
pandas_object \
256256
pandas.api.interchange.from_dataframe \
257-
pandas.Index.drop \
258-
pandas.Index.identical \
259-
pandas.Index.insert \
260-
pandas.Index.is_ \
261-
pandas.Index.take \
262-
pandas.Index.putmask \
263-
pandas.Index.unique \
264257
pandas.Index.fillna \
265258
pandas.Index.dropna \
266259
pandas.Index.astype \

pandas/core/indexes/base.py

+52
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,15 @@ def is_(self, other) -> bool:
812812
See Also
813813
--------
814814
Index.identical : Works like ``Index.is_`` but also checks metadata.
815+
816+
Examples
817+
--------
818+
>>> idx1 = pd.Index(['1', '2', '3'])
819+
>>> idx1.is_(idx1.view())
820+
True
821+
822+
>>> idx1.is_(idx1.copy())
823+
False
815824
"""
816825
if self is other:
817826
return True
@@ -1118,6 +1127,12 @@ def astype(self, dtype, copy: bool = True):
11181127
--------
11191128
numpy.ndarray.take: Return an array formed from the
11201129
elements of a at the given indices.
1130+
1131+
Examples
1132+
--------
1133+
>>> idx = pd.Index(['a', 'b', 'c'])
1134+
>>> idx.take([2, 2, 1, 2])
1135+
Index(['c', 'c', 'b', 'c'], dtype='object')
11211136
"""
11221137

11231138
@Appender(_index_shared_docs["take"] % _index_doc_kwargs)
@@ -2995,6 +3010,12 @@ def unique(self, level: Hashable | None = None) -> Self:
29953010
--------
29963011
unique : Numpy array of unique values in that column.
29973012
Series.unique : Return unique values of Series object.
3013+
3014+
Examples
3015+
--------
3016+
>>> idx = pd.Index([1, 1, 2, 3, 3])
3017+
>>> idx.unique()
3018+
Index([1, 2, 3], dtype='int64')
29983019
"""
29993020
if level is not None:
30003021
self._validate_index_level(level)
@@ -5388,6 +5409,13 @@ def putmask(self, mask, value) -> Index:
53885409
--------
53895410
numpy.ndarray.putmask : Changes elements of an array
53905411
based on conditional and input values.
5412+
5413+
Examples
5414+
--------
5415+
>>> idx1 = pd.Index([1, 2, 3])
5416+
>>> idx2 = pd.Index([5, 6, 7])
5417+
>>> idx1.putmask([True, False, False], idx2)
5418+
Index([5, 2, 3], dtype='int64')
53915419
"""
53925420
mask, noop = validate_putmask(self._values, mask)
53935421
if noop:
@@ -5517,6 +5545,18 @@ def identical(self, other) -> bool:
55175545
bool
55185546
If two Index objects have equal elements and same type True,
55195547
otherwise False.
5548+
5549+
Examples
5550+
--------
5551+
>>> idx1 = pd.Index(['1', '2', '3'])
5552+
>>> idx2 = pd.Index(['1', '2', '3'])
5553+
>>> idx2.identical(idx1)
5554+
True
5555+
5556+
>>> idx1 = pd.Index(['1', '2', '3'], name="A")
5557+
>>> idx2 = pd.Index(['1', '2', '3'], name="B")
5558+
>>> idx2.identical(idx1)
5559+
False
55205560
"""
55215561
return (
55225562
self.equals(other)
@@ -6737,6 +6777,12 @@ def insert(self, loc: int, item) -> Index:
67376777
Returns
67386778
-------
67396779
Index
6780+
6781+
Examples
6782+
--------
6783+
>>> idx = pd.Index(['a', 'b', 'c'])
6784+
>>> idx.insert(1, 'x')
6785+
Index(['a', 'x', 'b', 'c'], dtype='object')
67406786
"""
67416787
item = lib.item_from_zerodim(item)
67426788
if is_valid_na_for_dtype(item, self.dtype) and self.dtype != object:
@@ -6798,6 +6844,12 @@ def drop(
67986844
------
67996845
KeyError
68006846
If not all of the labels are found in the selected axis
6847+
6848+
Examples
6849+
--------
6850+
>>> idx = pd.Index(['a', 'b', 'c'])
6851+
>>> idx.drop(['a'])
6852+
Index(['b', 'c'], dtype='object')
68016853
"""
68026854
if not isinstance(labels, Index):
68036855
# avoid materializing e.g. RangeIndex

0 commit comments

Comments
 (0)