@@ -1013,6 +1013,42 @@ def ravel(self, order: str_t = "C") -> Self:
1013
1013
return self [:]
1014
1014
1015
1015
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
+ """
1016
1052
# we need to see if we are subclassing an
1017
1053
# index type here
1018
1054
if cls is not None :
0 commit comments