Skip to content

Commit

Permalink
FIX-#7056: Update exception message for iloc/loc functions (#7057)
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
  • Loading branch information
anmyachev authored Mar 12, 2024
1 parent c45eeaa commit 441be09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 1 addition & 3 deletions modin/pandas/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,7 @@ def _validate_key_length(self, key: tuple) -> tuple: # noqa: GL08
if Ellipsis in key:
raise IndexingError(_one_ellipsis_message)
return self._validate_key_length(key)
raise IndexingError(
f"Too many indexers: you're trying to pass {len(key)} indexers to the {type(self.df)} having only {self.df.ndim} dimensions."
)
raise IndexingError("Too many indexers")
return key

def __getitem__(self, key): # pragma: no cover
Expand Down
16 changes: 13 additions & 3 deletions modin/pandas/test/dataframe/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,10 +870,20 @@ def test_iloc_empty():
df_equals(pandas_df, modin_df)


def test_iloc_loc_key_length():
def test_iloc_loc_key_length_except():
modin_ser, pandas_ser = pd.Series(0), pandas.Series(0)
eval_general(modin_ser, pandas_ser, lambda ser: ser.iloc[0, 0])
eval_general(modin_ser, pandas_ser, lambda ser: ser.loc[0, 0])
eval_general(
modin_ser,
pandas_ser,
lambda ser: ser.iloc[0, 0],
raising_exceptions=pandas.errors.IndexingError("Too many indexers"),
)
eval_general(
modin_ser,
pandas_ser,
lambda ser: ser.loc[0, 0],
raising_exceptions=pandas.errors.IndexingError("Too many indexers"),
)


def test_loc_series():
Expand Down

0 comments on commit 441be09

Please sign in to comment.