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,33 @@ 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.
100
-
79
+ storing axis labels for all pandas objects. %(klass)s is a special case
80
+ of `Index` with purely integer labels. %(extra)s
101
81
Parameters
102
82
----------
103
83
data : array-like (1-dimensional)
104
- dtype : NumPy dtype (default: int64 )
84
+ dtype : NumPy dtype (default: %(dtype)s )
105
85
copy : bool
106
86
Make a copy of input ndarray
107
87
name : object
108
88
Name to be stored in the index
109
-
110
89
Notes
111
90
-----
112
- An Index instance can **only** contain hashable objects
113
- """
91
+ An Index instance can **only** contain hashable objects.
92
+ """
93
+
94
+ _int64_descr_args = dict (
95
+ klass = 'Int64Index' ,
96
+ dtype = 'int64' ,
97
+ extra = ('This is the default index type used by the DataFrame and Series '
98
+ 'ctors when no explicit index is provided by the user.' )
99
+ )
100
+
101
+
102
+ class Int64Index (NumericIndex ):
103
+ __doc__ = _num_index_shared_docs ['class_descr' ] % _int64_descr_args
114
104
115
105
_typ = 'int64index'
116
106
_arrmap = _algos .arrmap_int64
@@ -141,16 +131,8 @@ def is_all_dates(self):
141
131
"""
142
132
return False
143
133
134
+ @Appender (_index_shared_docs ['_convert_scalar_indexer' ])
144
135
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
136
assert kind in ['ix' , 'loc' , 'getitem' , 'iloc' , None ]
155
137
156
138
# don't coerce ilocs to integers
@@ -177,25 +159,15 @@ def _assert_safe_casting(cls, data, subarr):
177
159
Int64Index ._add_logical_methods ()
178
160
179
161
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.
162
+ _float64_descr_args = dict (
163
+ klass = 'Float64Index' ,
164
+ dtype = 'float64' ,
165
+ extra = ''
166
+ )
185
167
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
168
195
- Notes
196
- -----
197
- An Float64Index instance can **only** contain hashable objects
198
- """
169
+ class Float64Index (NumericIndex ):
170
+ __doc__ = _num_index_shared_docs ['class_descr' ] % _float64_descr_args
199
171
200
172
_typ = 'float64index'
201
173
_engine_type = _index .Float64Engine
@@ -228,6 +200,7 @@ def astype(self, dtype, copy=True):
228
200
self .__class__ )
229
201
return Index (values , name = self .name , dtype = dtype )
230
202
203
+ @Appender (_index_shared_docs ['_convert_scalar_indexer' ])
231
204
def _convert_scalar_indexer (self , key , kind = None ):
232
205
"""
233
206
convert a scalar indexer
@@ -245,17 +218,8 @@ def _convert_scalar_indexer(self, key, kind=None):
245
218
246
219
return key
247
220
221
+ @Appender (_index_shared_docs ['_convert_slice_indexer' ])
248
222
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
223
# if we are not a slice, then we are done
260
224
if not isinstance (key , slice ):
261
225
return key
@@ -325,6 +289,7 @@ def __contains__(self, other):
325
289
except :
326
290
return False
327
291
292
+ @Appender (_index_shared_docs ['get_loc' ])
328
293
def get_loc (self , key , method = None , tolerance = None ):
329
294
try :
330
295
if np .all (np .isnan (key )):
0 commit comments