diff --git a/modin/pandas/base.py b/modin/pandas/base.py index 6779c47dc9b..98d2e1d1520 100644 --- a/modin/pandas/base.py +++ b/modin/pandas/base.py @@ -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. diff --git a/modin/pandas/test/dataframe/test_map_metadata.py b/modin/pandas/test/dataframe/test_map_metadata.py index a47ab0cd850..40e1a7aded6 100644 --- a/modin/pandas/test/dataframe/test_map_metadata.py +++ b/modin/pandas/test/dataframe/test_map_metadata.py @@ -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" + ), ) diff --git a/modin/pandas/test/utils.py b/modin/pandas/test/utils.py index b350b9aa934..258e4af6b7d 100644 --- a/modin/pandas/test/utils.py +++ b/modin/pandas/test/utils.py @@ -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)}]"