@@ -6386,19 +6386,18 @@ def maybe_extract_name(name, obj, cls) -> Hashable:
6386
6386
return name
6387
6387
6388
6388
6389
- def _maybe_cast_data_without_dtype (subarr ) :
6389
+ def _maybe_cast_data_without_dtype (subarr : np . ndarray ) -> ArrayLike :
6390
6390
"""
6391
6391
If we have an arraylike input but no passed dtype, try to infer
6392
6392
a supported dtype.
6393
6393
6394
6394
Parameters
6395
6395
----------
6396
- subarr : np.ndarray, Index, or Series
6396
+ subarr : np.ndarray[object]
6397
6397
6398
6398
Returns
6399
6399
-------
6400
- converted : np.ndarray or ExtensionArray
6401
- dtype : np.dtype or ExtensionDtype
6400
+ np.ndarray or ExtensionArray
6402
6401
"""
6403
6402
# Runtime import needed bc IntervalArray imports Index
6404
6403
from pandas .core .arrays import (
@@ -6413,11 +6412,7 @@ def _maybe_cast_data_without_dtype(subarr):
6413
6412
6414
6413
if inferred == "integer" :
6415
6414
try :
6416
- # error: Argument 3 to "_try_convert_to_int_array" has incompatible type
6417
- # "None"; expected "dtype[Any]"
6418
- data = _try_convert_to_int_array (
6419
- subarr , False , None # type: ignore[arg-type]
6420
- )
6415
+ data = _try_convert_to_int_array (subarr )
6421
6416
return data
6422
6417
except ValueError :
6423
6418
pass
@@ -6463,18 +6458,13 @@ def _maybe_cast_data_without_dtype(subarr):
6463
6458
return subarr
6464
6459
6465
6460
6466
- def _try_convert_to_int_array (
6467
- data : np .ndarray , copy : bool , dtype : np .dtype
6468
- ) -> np .ndarray :
6461
+ def _try_convert_to_int_array (data : np .ndarray ) -> np .ndarray :
6469
6462
"""
6470
6463
Attempt to convert an array of data into an integer array.
6471
6464
6472
6465
Parameters
6473
6466
----------
6474
- data : The data to convert.
6475
- copy : bool
6476
- Whether to copy the data or not.
6477
- dtype : np.dtype
6467
+ data : np.ndarray[object]
6478
6468
6479
6469
Returns
6480
6470
-------
@@ -6484,22 +6474,19 @@ def _try_convert_to_int_array(
6484
6474
------
6485
6475
ValueError if the conversion was not successful.
6486
6476
"""
6487
- if not is_unsigned_integer_dtype (dtype ):
6488
- # skip int64 conversion attempt if uint-like dtype is passed, as
6489
- # this could return Int64Index when UInt64Index is what's desired
6490
- try :
6491
- res = data .astype ("i8" , copy = False )
6492
- if (res == data ).all ():
6493
- return res # TODO: might still need to copy
6494
- except (OverflowError , TypeError , ValueError ):
6495
- pass
6477
+ try :
6478
+ res = data .astype ("i8" , copy = False )
6479
+ if (res == data ).all ():
6480
+ return res
6481
+ except (OverflowError , TypeError , ValueError ):
6482
+ pass
6496
6483
6497
- # Conversion to int64 failed (possibly due to overflow) or was skipped ,
6484
+ # Conversion to int64 failed (possibly due to overflow),
6498
6485
# so let's try now with uint64.
6499
6486
try :
6500
6487
res = data .astype ("u8" , copy = False )
6501
6488
if (res == data ).all ():
6502
- return res # TODO: might still need to copy
6489
+ return res
6503
6490
except (OverflowError , TypeError , ValueError ):
6504
6491
pass
6505
6492
0 commit comments