1616import pandas .indexes .base as ibase
1717
1818
19+ _num_index_shared_docs = dict ()
20+
21+
1922class NumericIndex (Index ):
2023 """
2124 Provide numeric type operations
@@ -47,27 +50,8 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None,
4750 name = data .name
4851 return cls ._simple_new (subarr , name = name )
4952
53+ @Appender (_index_shared_docs ['_maybe_cast_slice_bound' ])
5054 def _maybe_cast_slice_bound (self , label , side , kind ):
51- """
52- This function should be overloaded in subclasses that allow non-trivial
53- casting on label-slice bounds, e.g. datetime-like indices allowing
54- strings containing formatted datetimes.
55-
56- Parameters
57- ----------
58- label : object
59- side : {'left', 'right'}
60- kind : {'ix', 'loc', 'getitem'}
61-
62- Returns
63- -------
64- label : object
65-
66- Notes
67- -----
68- Value of `side` parameter should be validated in caller.
69-
70- """
7155 assert kind in ['ix' , 'loc' , 'getitem' , None ]
7256
7357 # we will try to coerce to integers
@@ -90,27 +74,37 @@ def _assert_safe_casting(cls, data, subarr):
9074 pass
9175
9276
93- class Int64Index (NumericIndex ):
94- """
77+ _num_index_shared_docs ['class_descr' ] = """
9578 Immutable ndarray implementing an ordered, sliceable set. The basic object
96- storing axis labels for all pandas objects. Int64Index is a special case
97- of `Index` with purely integer labels. This is the default index type used
98- by the DataFrame and Series ctors when no explicit index is provided by the
99- user.
79+ storing axis labels for all pandas objects. %(klass)s is a special case
80+ of `Index` with purely %(ltype)s labels. %(extra)s
10081
10182 Parameters
10283 ----------
10384 data : array-like (1-dimensional)
104- dtype : NumPy dtype (default: int64 )
85+ dtype : NumPy dtype (default: %(dtype)s )
10586 copy : bool
10687 Make a copy of input ndarray
10788 name : object
10889 Name to be stored in the index
109-
11090 Notes
11191 -----
112- An Index instance can **only** contain hashable objects
113- """
92+ An Index instance can **only** contain hashable objects.
93+ """
94+
95+ _int64_descr_args = dict (
96+ klass = 'Int64Index' ,
97+ ltype = 'integer' ,
98+ dtype = 'int64' ,
99+ extra = """This is the default index type used
100+ by the DataFrame and Series ctors when no explicit
101+ index is provided by the user.
102+ """
103+ )
104+
105+
106+ class Int64Index (NumericIndex ):
107+ __doc__ = _num_index_shared_docs ['class_descr' ] % _int64_descr_args
114108
115109 _typ = 'int64index'
116110 _arrmap = _algos .arrmap_int64
@@ -141,16 +135,8 @@ def is_all_dates(self):
141135 """
142136 return False
143137
138+ @Appender (_index_shared_docs ['_convert_scalar_indexer' ])
144139 def _convert_scalar_indexer (self , key , kind = None ):
145- """
146- convert a scalar indexer
147-
148- Parameters
149- ----------
150- key : label of the slice bound
151- kind : {'ix', 'loc', 'getitem'} or None
152- """
153-
154140 assert kind in ['ix' , 'loc' , 'getitem' , 'iloc' , None ]
155141
156142 # don't coerce ilocs to integers
@@ -177,25 +163,16 @@ def _assert_safe_casting(cls, data, subarr):
177163Int64Index ._add_logical_methods ()
178164
179165
180- class Float64Index (NumericIndex ):
181- """
182- Immutable ndarray implementing an ordered, sliceable set. The basic object
183- storing axis labels for all pandas objects. Float64Index is a special case
184- of `Index` with purely floating point labels.
166+ _float64_descr_args = dict (
167+ klass = 'Float64Index' ,
168+ dtype = 'float64' ,
169+ ltype = 'float' ,
170+ extra = ''
171+ )
185172
186- Parameters
187- ----------
188- data : array-like (1-dimensional)
189- dtype : NumPy dtype (default: object)
190- copy : bool
191- Make a copy of input ndarray
192- name : object
193- Name to be stored in the index
194173
195- Notes
196- -----
197- An Float64Index instance can **only** contain hashable objects
198- """
174+ class Float64Index (NumericIndex ):
175+ __doc__ = _num_index_shared_docs ['class_descr' ] % _float64_descr_args
199176
200177 _typ = 'float64index'
201178 _engine_type = _index .Float64Engine
@@ -228,6 +205,7 @@ def astype(self, dtype, copy=True):
228205 self .__class__ )
229206 return Index (values , name = self .name , dtype = dtype )
230207
208+ @Appender (_index_shared_docs ['_convert_scalar_indexer' ])
231209 def _convert_scalar_indexer (self , key , kind = None ):
232210 """
233211 convert a scalar indexer
@@ -245,17 +223,8 @@ def _convert_scalar_indexer(self, key, kind=None):
245223
246224 return key
247225
226+ @Appender (_index_shared_docs ['_convert_slice_indexer' ])
248227 def _convert_slice_indexer (self , key , kind = None ):
249- """
250- convert a slice indexer, by definition these are labels
251- unless we are iloc
252-
253- Parameters
254- ----------
255- key : label of the slice bound
256- kind : optional, type of the indexing operation (loc/ix/iloc/None)
257- """
258-
259228 # if we are not a slice, then we are done
260229 if not isinstance (key , slice ):
261230 return key
@@ -325,6 +294,7 @@ def __contains__(self, other):
325294 except :
326295 return False
327296
297+ @Appender (_index_shared_docs ['get_loc' ])
328298 def get_loc (self , key , method = None , tolerance = None ):
329299 try :
330300 if np .all (np .isnan (key )):
0 commit comments