Skip to content

Commit c44e030

Browse files
DeaMariaLeontopper-123
authored andcommitted
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 9a1bfea commit c44e030

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
@@ -803,6 +803,15 @@ def is_(self, other) -> bool:
803803
See Also
804804
--------
805805
Index.identical : Works like ``Index.is_`` but also checks metadata.
806+
807+
Examples
808+
--------
809+
>>> idx1 = pd.Index(['1', '2', '3'])
810+
>>> idx1.is_(idx1.view())
811+
True
812+
813+
>>> idx1.is_(idx1.copy())
814+
False
806815
"""
807816
if self is other:
808817
return True
@@ -1109,6 +1118,12 @@ def astype(self, dtype, copy: bool = True):
11091118
--------
11101119
numpy.ndarray.take: Return an array formed from the
11111120
elements of a at the given indices.
1121+
1122+
Examples
1123+
--------
1124+
>>> idx = pd.Index(['a', 'b', 'c'])
1125+
>>> idx.take([2, 2, 1, 2])
1126+
Index(['c', 'c', 'b', 'c'], dtype='object')
11121127
"""
11131128

11141129
@Appender(_index_shared_docs["take"] % _index_doc_kwargs)
@@ -2986,6 +3001,12 @@ def unique(self, level: Hashable | None = None) -> Self:
29863001
--------
29873002
unique : Numpy array of unique values in that column.
29883003
Series.unique : Return unique values of Series object.
3004+
3005+
Examples
3006+
--------
3007+
>>> idx = pd.Index([1, 1, 2, 3, 3])
3008+
>>> idx.unique()
3009+
Index([1, 2, 3], dtype='int64')
29893010
"""
29903011
if level is not None:
29913012
self._validate_index_level(level)
@@ -5379,6 +5400,13 @@ def putmask(self, mask, value) -> Index:
53795400
--------
53805401
numpy.ndarray.putmask : Changes elements of an array
53815402
based on conditional and input values.
5403+
5404+
Examples
5405+
--------
5406+
>>> idx1 = pd.Index([1, 2, 3])
5407+
>>> idx2 = pd.Index([5, 6, 7])
5408+
>>> idx1.putmask([True, False, False], idx2)
5409+
Index([5, 2, 3], dtype='int64')
53825410
"""
53835411
mask, noop = validate_putmask(self._values, mask)
53845412
if noop:
@@ -5508,6 +5536,18 @@ def identical(self, other) -> bool:
55085536
bool
55095537
If two Index objects have equal elements and same type True,
55105538
otherwise False.
5539+
5540+
Examples
5541+
--------
5542+
>>> idx1 = pd.Index(['1', '2', '3'])
5543+
>>> idx2 = pd.Index(['1', '2', '3'])
5544+
>>> idx2.identical(idx1)
5545+
True
5546+
5547+
>>> idx1 = pd.Index(['1', '2', '3'], name="A")
5548+
>>> idx2 = pd.Index(['1', '2', '3'], name="B")
5549+
>>> idx2.identical(idx1)
5550+
False
55115551
"""
55125552
return (
55135553
self.equals(other)
@@ -6728,6 +6768,12 @@ def insert(self, loc: int, item) -> Index:
67286768
Returns
67296769
-------
67306770
Index
6771+
6772+
Examples
6773+
--------
6774+
>>> idx = pd.Index(['a', 'b', 'c'])
6775+
>>> idx.insert(1, 'x')
6776+
Index(['a', 'x', 'b', 'c'], dtype='object')
67316777
"""
67326778
item = lib.item_from_zerodim(item)
67336779
if is_valid_na_for_dtype(item, self.dtype) and self.dtype != object:
@@ -6789,6 +6835,12 @@ def drop(
67896835
------
67906836
KeyError
67916837
If not all of the labels are found in the selected axis
6838+
6839+
Examples
6840+
--------
6841+
>>> idx = pd.Index(['a', 'b', 'c'])
6842+
>>> idx.drop(['a'])
6843+
Index(['b', 'c'], dtype='object')
67926844
"""
67936845
if not isinstance(labels, Index):
67946846
# avoid materializing e.g. RangeIndex

0 commit comments

Comments
 (0)