3535from pandas .core .dtypes .cast import infer_dtype_from_scalar
3636from pandas .core .dtypes .common import (
3737 DT64NS_DTYPE ,
38+ ensure_int64 ,
3839 is_dtype_equal ,
3940 is_extension_array_dtype ,
4041 is_list_like ,
@@ -1293,7 +1294,7 @@ def insert(
12931294
12941295 def reindex_indexer (
12951296 self : T ,
1296- new_axis ,
1297+ new_axis : Index ,
12971298 indexer ,
12981299 axis : int ,
12991300 fill_value = None ,
@@ -1359,7 +1360,10 @@ def reindex_indexer(
13591360 return type (self ).from_blocks (new_blocks , new_axes )
13601361
13611362 def _slice_take_blocks_ax0 (
1362- self , slice_or_indexer , fill_value = lib .no_default , only_slice : bool = False
1363+ self ,
1364+ slice_or_indexer : Union [slice , np .ndarray ],
1365+ fill_value = lib .no_default ,
1366+ only_slice : bool = False ,
13631367 ) -> List [Block ]:
13641368 """
13651369 Slice/take blocks along axis=0.
@@ -1368,7 +1372,7 @@ def _slice_take_blocks_ax0(
13681372
13691373 Parameters
13701374 ----------
1371- slice_or_indexer : slice, ndarray[bool], or list-like of ints
1375+ slice_or_indexer : slice or np. ndarray[int64]
13721376 fill_value : scalar, default lib.no_default
13731377 only_slice : bool, default False
13741378 If True, we always return views on existing arrays, never copies.
@@ -1387,12 +1391,11 @@ def _slice_take_blocks_ax0(
13871391 if self .is_single_block :
13881392 blk = self .blocks [0 ]
13891393
1390- if sl_type in ( "slice" , "mask" ) :
1394+ if sl_type == "slice" :
13911395 # GH#32959 EABlock would fail since we can't make 0-width
13921396 # TODO(EA2D): special casing unnecessary with 2D EAs
13931397 if sllen == 0 :
13941398 return []
1395- # TODO: tests all have isinstance(slobj, slice), other possibilities?
13961399 return [blk .getitem_block (slobj , new_mgr_locs = slice (0 , sllen ))]
13971400 elif not allow_fill or self .ndim == 1 :
13981401 if allow_fill and fill_value is None :
@@ -1418,7 +1421,7 @@ def _slice_take_blocks_ax0(
14181421 )
14191422 ]
14201423
1421- if sl_type in ( "slice" , "mask" ) :
1424+ if sl_type == "slice" :
14221425 blknos = self .blknos [slobj ]
14231426 blklocs = self .blklocs [slobj ]
14241427 else :
@@ -1661,9 +1664,6 @@ def get_slice(self, slobj: slice, axis: int = 0) -> SingleBlockManager:
16611664
16621665 blk = self ._block
16631666 array = blk ._slice (slobj )
1664- if array .ndim > blk .values .ndim :
1665- # This will be caught by Series._get_values
1666- raise ValueError ("dimension-expanding indexing not allowed" )
16671667 block = blk .make_block_same_class (array , placement = slice (0 , len (array )))
16681668 new_index = self .index ._getitem_slice (slobj )
16691669 return type (self )(block , new_index )
@@ -1978,10 +1978,6 @@ def _merge_blocks(
19781978
19791979 if can_consolidate :
19801980
1981- if dtype is None :
1982- if len ({b .dtype for b in blocks }) != 1 :
1983- raise AssertionError ("_merge_blocks are invalid!" )
1984-
19851981 # TODO: optimization potential in case all mgrs contain slices and
19861982 # combination of those slices is a slice, too.
19871983 new_mgr_locs = np .concatenate ([b .mgr_locs .as_array for b in blocks ])
@@ -2008,20 +2004,25 @@ def _fast_count_smallints(arr: np.ndarray) -> np.ndarray:
20082004 return np .c_ [nz , counts [nz ]]
20092005
20102006
2011- def _preprocess_slice_or_indexer (slice_or_indexer , length : int , allow_fill : bool ):
2007+ def _preprocess_slice_or_indexer (
2008+ slice_or_indexer : Union [slice , np .ndarray ], length : int , allow_fill : bool
2009+ ):
20122010 if isinstance (slice_or_indexer , slice ):
20132011 return (
20142012 "slice" ,
20152013 slice_or_indexer ,
20162014 libinternals .slice_len (slice_or_indexer , length ),
20172015 )
2018- elif (
2019- isinstance (slice_or_indexer , np .ndarray ) and slice_or_indexer .dtype == np .bool_
2020- ):
2021- return "mask" , slice_or_indexer , slice_or_indexer .sum ()
20222016 else :
2017+ if (
2018+ not isinstance (slice_or_indexer , np .ndarray )
2019+ or slice_or_indexer .dtype .kind != "i"
2020+ ):
2021+ dtype = getattr (slice_or_indexer , "dtype" , None )
2022+ raise TypeError (type (slice_or_indexer ), dtype )
2023+
20232024 # TODO: np.intp?
2024- indexer = np . asanyarray (slice_or_indexer , dtype = np . int64 )
2025+ indexer = ensure_int64 (slice_or_indexer )
20252026 if not allow_fill :
20262027 indexer = maybe_convert_indices (indexer , length )
20272028 return "fancy" , indexer , len (indexer )
0 commit comments