in core/maxframe/dataframe/indexing/iloc.py [0:0]
def process_iloc_indexes(inp, indexes):
ndim = inp.ndim
if not isinstance(indexes, tuple):
indexes = (indexes,)
if len(indexes) < ndim:
indexes += (slice(None),) * (ndim - len(indexes))
if len(indexes) > ndim:
raise IndexingError("Too many indexers")
new_indexes = []
# check each index
for ax, index in enumerate(indexes):
if isinstance(index, tuple):
# a tuple should already have been caught by this point
# so don't treat a tuple as a valid indexer
raise IndexingError("Too many indexers")
elif isinstance(index, slice):
if any(v is not None for v in [index.start, index.stop, index.step]):
pd_index = (
inp.index_value if ax == 0 else inp.columns_value
).to_pandas()
for val in [index.start, index.stop, index.step]:
if val is not None:
try:
pd_index[val] # check on the pandas
except IndexError:
pass
except TypeError:
raise TypeError(
f"cannot do slice indexing on {type(pd_index)} "
f"with these indexers [{val}] of {type(val)}"
)
new_indexes.append(index)
elif isinstance(index, (list, np.ndarray, pd.Series, ENTITY_TYPE)):
if not isinstance(index, ENTITY_TYPE):
index = np.asarray(index)
else:
index = asarray(index)
if ax == 1:
# do not support tensor index on axis 1
# because if so, the dtypes and columns_value would be unknown
try:
index = index.fetch()
except (RuntimeError, ValueError):
raise NotImplementedError(
"indexer on axis columns cannot be non-executed tensor"
)
if index.dtype != np.bool_:
index = index.astype(np.int64)
if index.ndim != 1:
raise ValueError(
"Buffer has wrong number of dimensions "
f"(expected 1, got {index.ndim})"
)
new_indexes.append(index)
elif isinstance(index, Integral):
shape = inp.shape[ax]
if not np.isnan(shape):
if index < -shape or index >= shape:
raise IndexError("single positional indexer is out-of-bounds")
new_indexes.append(index)
else:
raise ValueError(_ILOC_ERROR_MSG)
return new_indexes