diff --git a/pandas/core/series.py b/pandas/core/series.py index bfe9969daaa8e..040fcf392733b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -23,6 +23,7 @@ from pandas._config import get_option from pandas._libs import lib, properties, reshape, tslibs +from pandas._libs.index import validate_numeric_casting from pandas._typing import Label from pandas.compat.numpy import function as nv from pandas.util._decorators import Appender, Substitution @@ -1022,7 +1023,7 @@ def __setitem__(self, key, value): def _set_with_engine(self, key, value): # fails with AttributeError for IntervalIndex loc = self.index._engine.get_loc(key) - libindex.validate_numeric_casting(self.dtype, value) + validate_numeric_casting(self.dtype, value) self._values[loc] = value def _set_with(self, key, value): @@ -1105,7 +1106,7 @@ def _set_value(self, label, value, takeable: bool = False): self._values[label] = value else: loc = self.index.get_loc(label) - libindex.validate_numeric_casting(self.dtype, value) + validate_numeric_casting(self.dtype, value) self._values[loc] = value except KeyError: diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 097e83d93ee71..4c917b9bb42d2 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -675,6 +675,8 @@ def test__get_dtype(input_param, result): ) def test__get_dtype_fails(input_param, expected_error_message): # python objects + # 2020-02-02 npdev changed error message + expected_error_message += f"|Cannot interpret '{input_param}' as a data type" with pytest.raises(TypeError, match=expected_error_message): com._get_dtype(input_param) diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index 8df222e8fb59d..67c4fef7079e2 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -40,7 +40,12 @@ def test_equality_invalid(self, dtype): assert not is_dtype_equal(dtype, np.int64) def test_numpy_informed(self, dtype): - with pytest.raises(TypeError, match="data type not understood"): + # npdev 2020-02-02 changed from "data type not understood" to + # "Cannot interpret 'foo' as a data type" + msg = "|".join( + ["data type not understood", "Cannot interpret '.*' as a data type"] + ) + with pytest.raises(TypeError, match=msg): np.dtype(dtype) assert not dtype == np.str_