@@ -201,12 +201,21 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None,
201
201
202
202
# if we are actually all equal to integers
203
203
# then coerce to integer
204
- from .numeric import Int64Index , Float64Index
204
+ from .numeric import (Int64Index , UInt64Index ,
205
+ Float64Index )
205
206
try :
206
207
res = data .astype ('i8' )
207
208
if (res == data ).all ():
208
209
return Int64Index (res , copy = copy ,
209
210
name = name )
211
+ except (OverflowError , TypeError , ValueError ):
212
+ pass
213
+
214
+ try :
215
+ res = data .astype ('u8' )
216
+ if (res == data ).all ():
217
+ return UInt64Index (res , copy = copy ,
218
+ name = name )
210
219
except (TypeError , ValueError ):
211
220
pass
212
221
@@ -235,9 +244,12 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None,
235
244
IncompatibleFrequency )
236
245
if isinstance (data , PeriodIndex ):
237
246
return PeriodIndex (data , copy = copy , name = name , ** kwargs )
238
- if issubclass (data .dtype .type , np .integer ):
247
+ if issubclass (data .dtype .type , np .signedinteger ):
239
248
from .numeric import Int64Index
240
249
return Int64Index (data , copy = copy , dtype = dtype , name = name )
250
+ elif issubclass (data .dtype .type , np .unsignedinteger ):
251
+ from .numeric import UInt64Index
252
+ return UInt64Index (data , copy = copy , dtype = dtype , name = name )
241
253
elif issubclass (data .dtype .type , np .floating ):
242
254
from .numeric import Float64Index
243
255
return Float64Index (data , copy = copy , dtype = dtype , name = name )
@@ -254,9 +266,13 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None,
254
266
if dtype is None :
255
267
inferred = lib .infer_dtype (subarr )
256
268
if inferred == 'integer' :
257
- from .numeric import Int64Index
258
- return Int64Index (subarr .astype ('i8' ), copy = copy ,
259
- name = name )
269
+ from .numeric import Int64Index , UInt64Index
270
+ try :
271
+ return Int64Index (subarr .astype ('i8' ), copy = copy ,
272
+ name = name )
273
+ except OverflowError :
274
+ return UInt64Index (subarr .astype ('u8' ), copy = copy ,
275
+ name = name )
260
276
elif inferred in ['floating' , 'mixed-integer-float' ]:
261
277
from .numeric import Float64Index
262
278
return Float64Index (subarr , copy = copy , name = name )
0 commit comments