16
16
import pandas .indexes .base as ibase
17
17
18
18
19
+ _num_index_shared_docs = dict ()
20
+
21
+
19
22
class NumericIndex (Index ):
20
23
"""
21
24
Provide numeric type operations
@@ -47,27 +50,8 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None,
47
50
name = data .name
48
51
return cls ._simple_new (subarr , name = name )
49
52
53
+ @Appender (_index_shared_docs ['_maybe_cast_slice_bound' ])
50
54
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
- """
71
55
assert kind in ['ix' , 'loc' , 'getitem' , None ]
72
56
73
57
# we will try to coerce to integers
@@ -90,27 +74,37 @@ def _assert_safe_casting(cls, data, subarr):
90
74
pass
91
75
92
76
93
- class Int64Index (NumericIndex ):
94
- """
77
+ _num_index_shared_docs ['class_descr' ] = """
95
78
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
100
81
101
82
Parameters
102
83
----------
103
84
data : array-like (1-dimensional)
104
- dtype : NumPy dtype (default: int64 )
85
+ dtype : NumPy dtype (default: %(dtype)s )
105
86
copy : bool
106
87
Make a copy of input ndarray
107
88
name : object
108
89
Name to be stored in the index
109
-
110
90
Notes
111
91
-----
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
114
108
115
109
_typ = 'int64index'
116
110
_arrmap = _algos .arrmap_int64
@@ -141,16 +135,8 @@ def is_all_dates(self):
141
135
"""
142
136
return False
143
137
138
+ @Appender (_index_shared_docs ['_convert_scalar_indexer' ])
144
139
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
-
154
140
assert kind in ['ix' , 'loc' , 'getitem' , 'iloc' , None ]
155
141
156
142
# don't coerce ilocs to integers
@@ -177,25 +163,16 @@ def _assert_safe_casting(cls, data, subarr):
177
163
Int64Index ._add_logical_methods ()
178
164
179
165
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
+ )
185
172
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
194
173
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
199
176
200
177
_typ = 'float64index'
201
178
_engine_type = _index .Float64Engine
@@ -228,6 +205,7 @@ def astype(self, dtype, copy=True):
228
205
self .__class__ )
229
206
return Index (values , name = self .name , dtype = dtype )
230
207
208
+ @Appender (_index_shared_docs ['_convert_scalar_indexer' ])
231
209
def _convert_scalar_indexer (self , key , kind = None ):
232
210
"""
233
211
convert a scalar indexer
@@ -245,17 +223,8 @@ def _convert_scalar_indexer(self, key, kind=None):
245
223
246
224
return key
247
225
226
+ @Appender (_index_shared_docs ['_convert_slice_indexer' ])
248
227
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
-
259
228
# if we are not a slice, then we are done
260
229
if not isinstance (key , slice ):
261
230
return key
@@ -325,6 +294,7 @@ def __contains__(self, other):
325
294
except :
326
295
return False
327
296
297
+ @Appender (_index_shared_docs ['get_loc' ])
328
298
def get_loc (self , key , method = None , tolerance = None ):
329
299
try :
330
300
if np .all (np .isnan (key )):
0 commit comments