@@ -6386,19 +6386,18 @@ def maybe_extract_name(name, obj, cls) -> Hashable:
63866386 return name
63876387
63886388
6389- def _maybe_cast_data_without_dtype (subarr ) :
6389+ def _maybe_cast_data_without_dtype (subarr : np . ndarray ) -> ArrayLike :
63906390 """
63916391 If we have an arraylike input but no passed dtype, try to infer
63926392 a supported dtype.
63936393
63946394 Parameters
63956395 ----------
6396- subarr : np.ndarray, Index, or Series
6396+ subarr : np.ndarray[object]
63976397
63986398 Returns
63996399 -------
6400- converted : np.ndarray or ExtensionArray
6401- dtype : np.dtype or ExtensionDtype
6400+ np.ndarray or ExtensionArray
64026401 """
64036402 # Runtime import needed bc IntervalArray imports Index
64046403 from pandas .core .arrays import (
@@ -6413,11 +6412,7 @@ def _maybe_cast_data_without_dtype(subarr):
64136412
64146413 if inferred == "integer" :
64156414 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 )
64216416 return data
64226417 except ValueError :
64236418 pass
@@ -6463,18 +6458,13 @@ def _maybe_cast_data_without_dtype(subarr):
64636458 return subarr
64646459
64656460
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 :
64696462 """
64706463 Attempt to convert an array of data into an integer array.
64716464
64726465 Parameters
64736466 ----------
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]
64786468
64796469 Returns
64806470 -------
@@ -6484,22 +6474,19 @@ def _try_convert_to_int_array(
64846474 ------
64856475 ValueError if the conversion was not successful.
64866476 """
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
64966483
6497- # Conversion to int64 failed (possibly due to overflow) or was skipped ,
6484+ # Conversion to int64 failed (possibly due to overflow),
64986485 # so let's try now with uint64.
64996486 try :
65006487 res = data .astype ("u8" , copy = False )
65016488 if (res == data ).all ():
6502- return res # TODO: might still need to copy
6489+ return res
65036490 except (OverflowError , TypeError , ValueError ):
65046491 pass
65056492
0 commit comments