Skip to content

Commit

Permalink
FIX-modin-project#7051: Update exception message for 'astype' function (
Browse files Browse the repository at this point in the history
modin-project#7052)

Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
  • Loading branch information
anmyachev authored Mar 12, 2024
1 parent fe3a229 commit 4ab68c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 1 addition & 5 deletions modin/pandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,11 +1005,7 @@ def astype(self, dtype, copy=None, errors="raise"): # noqa: PR01, RT01, D200
# convert it to a dict before passing it to the query compiler.
if isinstance(dtype, (pd.Series, pandas.Series)):
if not dtype.index.is_unique:
raise ValueError(
"The new Series of types must have a unique index, i.e. "
+ "it must be one-to-one mapping from column names to "
+ " their new dtypes."
)
raise ValueError("cannot reindex on an axis with duplicate labels")
dtype = {column: dtype for column, dtype in dtype.items()}
# If we got a series or dict originally, dtype is a dict now. Its keys
# must be column names.
Expand Down
3 changes: 3 additions & 0 deletions modin/pandas/test/dataframe/test_map_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ def test_astype():
if isinstance(df, pd.DataFrame)
else pandas.Series([str, str], index=["col1", "col1"])
),
raising_exceptions=ValueError(
"cannot reindex on an axis with duplicate labels"
),
)


Expand Down
10 changes: 9 additions & 1 deletion modin/pandas/test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,10 +900,18 @@ def execute_callable(fn, inplace=False, md_kwargs={}, pd_kwargs={}):
), "Got Modin Exception type {}, but pandas Exception type {} was expected".format(
type(md_e), type(pd_e)
)
if raising_exceptions:
if raising_exceptions and isinstance(raising_exceptions, (list, tuple)):
assert not isinstance(
md_e, tuple(raising_exceptions)
), f"not acceptable exception type: {md_e}"
elif raising_exceptions and type(raising_exceptions) is type:
assert (
type(md_e) is type(raising_exceptions)
and md_e.args == raising_exceptions.args
), f"not acceptable Modin's exception: [{repr(md_e)}]"
assert (
pd_e.args == raising_exceptions.args
), f"not acceptable Pandas' exception: [{repr(pd_e)}]"
else:
raise NoModinException(
f"Modin doesn't throw an exception, while pandas does: [{repr(pd_e)}]"
Expand Down

0 comments on commit 4ab68c6

Please sign in to comment.