From ad2447cd2794adac7a74de3b0f65e775db780867 Mon Sep 17 00:00:00 2001 From: srkds Date: Sat, 22 Apr 2023 23:29:47 +0530 Subject: [PATCH] TST: cast string to complex --- pandas/tests/dtypes/test_dtypes.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index 5b0fcd5383059..745a933f3a780 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -1161,6 +1161,13 @@ def test_compare_complex_dtypes(): df.lt(df.astype(object)) +def test_cast_string_to_complex(): + # GH 4895 + expected = pd.DataFrame(["1.0+5j", "1.5-3j"], dtype=complex) + result = pd.DataFrame(["1.0+5j", "1.5-3j"]).astype(complex) + tm.assert_frame_equal(result, expected) + + def test_multi_column_dtype_assignment(): # GH #27583 df = pd.DataFrame({"a": [0.0], "b": 0.0})