From 9920297ffdacde0a04b00dc44d66af713d2249f2 Mon Sep 17 00:00:00 2001 From: Daniel Saxton <> Date: Thu, 19 Sep 2019 13:14:46 -0400 Subject: [PATCH 1/3] TST: Add astype_nansafe datetime tests --- pandas/tests/dtypes/test_common.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 266f7ac50c663..3df53cda32af1 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -3,6 +3,7 @@ import pandas.util._test_decorators as td +from pandas.core.dtypes.cast import astype_nansafe import pandas.core.dtypes.common as com from pandas.core.dtypes.dtypes import ( CategoricalDtype, @@ -706,3 +707,14 @@ def test__get_dtype_fails(input_param, expected_error_message): ) def test__is_dtype_type(input_param, result): assert com._is_dtype_type(input_param, lambda tipo: tipo == result) + + +@pytest.mark.parametrize("from_type", [np.datetime64, np.timedelta64]) +@pytest.mark.parametrize( + "to_type", [np.int8, np.int16, np.int32, np.float16, np.float32] +) +def test_astype_datetime64_bad_dtype(from_type, to_type): + arr = np.array([from_type("2018")]) + + with pytest.raises(TypeError, match="cannot astype"): + astype_nansafe(arr, dtype=to_type) From e8b324daff0c1fea18ed0f785e44398ce3d61bb6 Mon Sep 17 00:00:00 2001 From: Daniel Saxton <> Date: Thu, 19 Sep 2019 19:55:22 -0400 Subject: [PATCH 2/3] Add some uint types --- pandas/tests/dtypes/test_common.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 3df53cda32af1..d2b53ccc65577 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -711,7 +711,17 @@ def test__is_dtype_type(input_param, result): @pytest.mark.parametrize("from_type", [np.datetime64, np.timedelta64]) @pytest.mark.parametrize( - "to_type", [np.int8, np.int16, np.int32, np.float16, np.float32] + "to_type", + [ + np.uint8, + np.uint16, + np.uint32, + np.int8, + np.int16, + np.int32, + np.float16, + np.float32, + ], ) def test_astype_datetime64_bad_dtype(from_type, to_type): arr = np.array([from_type("2018")]) From 2b598f5b690201cba5517ae63c89dce5f555ee5f Mon Sep 17 00:00:00 2001 From: Daniel Saxton <> Date: Fri, 20 Sep 2019 09:24:38 -0400 Subject: [PATCH 3/3] Edit test name --- pandas/tests/dtypes/test_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index d2b53ccc65577..04e8b329a0b40 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -723,7 +723,7 @@ def test__is_dtype_type(input_param, result): np.float32, ], ) -def test_astype_datetime64_bad_dtype(from_type, to_type): +def test_astype_datetime64_bad_dtype_raises(from_type, to_type): arr = np.array([from_type("2018")]) with pytest.raises(TypeError, match="cannot astype"):