33
33
34
34
from pandas .core .dtypes .cast import construct_1d_object_array_from_listlike
35
35
from pandas .core .dtypes .common import (
36
- is_array_like ,
37
36
is_bool_dtype ,
38
37
is_integer ,
39
38
)
40
- from pandas .core .dtypes .dtypes import ExtensionDtype
41
39
from pandas .core .dtypes .generic import (
42
40
ABCExtensionArray ,
43
41
ABCIndex ,
@@ -120,9 +118,7 @@ def is_bool_indexer(key: Any) -> bool:
120
118
check_array_indexer : Check that `key` is a valid array to index,
121
119
and convert to an ndarray.
122
120
"""
123
- if isinstance (key , (ABCSeries , np .ndarray , ABCIndex )) or (
124
- is_array_like (key ) and isinstance (key .dtype , ExtensionDtype )
125
- ):
121
+ if isinstance (key , (ABCSeries , np .ndarray , ABCIndex , ABCExtensionArray )):
126
122
if key .dtype == np .object_ :
127
123
key_array = np .asarray (key )
128
124
@@ -420,7 +416,7 @@ def random_state(state: np.random.Generator) -> np.random.Generator:
420
416
421
417
@overload
422
418
def random_state (
423
- state : int | ArrayLike | np .random .BitGenerator | np .random .RandomState | None ,
419
+ state : int | np . ndarray | np .random .BitGenerator | np .random .RandomState | None ,
424
420
) -> np .random .RandomState :
425
421
...
426
422
@@ -445,24 +441,8 @@ def random_state(state: RandomState | None = None):
445
441
np.random.RandomState or np.random.Generator. If state is None, returns np.random
446
442
447
443
"""
448
- if (
449
- is_integer (state )
450
- or is_array_like (state )
451
- or isinstance (state , np .random .BitGenerator )
452
- ):
453
- # error: Argument 1 to "RandomState" has incompatible type "Optional[Union[int,
454
- # Union[ExtensionArray, ndarray[Any, Any]], Generator, RandomState]]"; expected
455
- # "Union[None, Union[Union[_SupportsArray[dtype[Union[bool_, integer[Any]]]],
456
- # Sequence[_SupportsArray[dtype[Union[bool_, integer[Any]]]]],
457
- # Sequence[Sequence[_SupportsArray[dtype[Union[bool_, integer[Any]]]]]],
458
- # Sequence[Sequence[Sequence[_SupportsArray[dtype[Union[bool_,
459
- # integer[Any]]]]]]],
460
- # Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[Union[bool_,
461
- # integer[Any]]]]]]]]], Union[bool, int, Sequence[Union[bool, int]],
462
- # Sequence[Sequence[Union[bool, int]]], Sequence[Sequence[Sequence[Union[bool,
463
- # int]]]], Sequence[Sequence[Sequence[Sequence[Union[bool, int]]]]]]],
464
- # BitGenerator]"
465
- return np .random .RandomState (state ) # type: ignore[arg-type]
444
+ if is_integer (state ) or isinstance (state , (np .ndarray , np .random .BitGenerator )):
445
+ return np .random .RandomState (state )
466
446
elif isinstance (state , np .random .RandomState ):
467
447
return state
468
448
elif isinstance (state , np .random .Generator ):
0 commit comments