Skip to content

Commit 1ee9186

Browse files
tuhinsharma121pmhatre1
authored andcommitted
DOC: Enforce Numpy Docstring Validation for pandas.Index.view (pandas-dev#58486)
* DOC: add GL08 for pandas.Index.view * DOC: remove GL08 for pandas.Index.view * DOC: fix examples in docstring * DOC: fix examples in docstring * DOC: fix examples in docstring * DOC: fix examples in docstring * DOC: fix examples in docstring
1 parent b25ecbc commit 1ee9186

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
9999
-i "pandas.Index.putmask PR01,RT03" \
100100
-i "pandas.Index.ravel PR01,RT03" \
101101
-i "pandas.Index.str PR01,SA01" \
102-
-i "pandas.Index.view GL08" \
103102
-i "pandas.Int16Dtype SA01" \
104103
-i "pandas.Int32Dtype SA01" \
105104
-i "pandas.Int64Dtype SA01" \

pandas/core/indexes/base.py

+36
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,42 @@ def ravel(self, order: str_t = "C") -> Self:
10131013
return self[:]
10141014

10151015
def view(self, cls=None):
1016+
"""
1017+
Return a view on self.
1018+
1019+
Parameters
1020+
----------
1021+
cls : data-type or ndarray sub-class, optional
1022+
Data-type descriptor of the returned view, e.g., float32 or int16.
1023+
Omitting it results in the view having the same data-type as `self`.
1024+
This argument can also be specified as an ndarray sub-class,
1025+
e.g., np.int64 or np.float32 which then specifies the type of
1026+
the returned object.
1027+
1028+
Returns
1029+
-------
1030+
numpy.ndarray
1031+
A new view of the same data in memory.
1032+
1033+
See Also
1034+
--------
1035+
numpy.ndarray.view : Returns a new view of array with the same data.
1036+
1037+
Examples
1038+
--------
1039+
>>> s = pd.Series([1, 2, 3], index=["1", "2", "3"])
1040+
>>> s.index.view("object")
1041+
array(['1', '2', '3'], dtype=object)
1042+
1043+
>>> s = pd.Series([1, 2, 3], index=[-1, 0, 1])
1044+
>>> s.index.view(np.int64)
1045+
array([-1, 0, 1])
1046+
>>> s.index.view(np.float32)
1047+
array([ nan, nan, 0.e+00, 0.e+00, 1.e-45, 0.e+00], dtype=float32)
1048+
>>> s.index.view(np.uint64)
1049+
array([18446744073709551615, 0, 1],
1050+
dtype=uint64)
1051+
"""
10161052
# we need to see if we are subclassing an
10171053
# index type here
10181054
if cls is not None:

0 commit comments

Comments
 (0)