diff options
author | zjpoh <poh.zijie@gmail.com> | 2019-08-07 23:03:08 -0700 |
---|---|---|
committer | zjpoh <poh.zijie@gmail.com> | 2019-08-07 23:03:08 -0700 |
commit | b112fc371815fbd1fa5e1f121ffee9aa563092f1 (patch) | |
tree | b75f76e2cd663cdca1ec7305e52e743155ce8701 /numpy/core/tests | |
parent | 67940ffec87b75ff72250ae9b2890fac6a134681 (diff) | |
download | numpy-b112fc371815fbd1fa5e1f121ffee9aa563092f1.tar.gz |
Parse complex number from string
Diffstat (limited to 'numpy/core/tests')
-rw-r--r-- | numpy/core/tests/test_longdouble.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/numpy/core/tests/test_longdouble.py b/numpy/core/tests/test_longdouble.py index ee4197f8f..ad4d7a357 100644 --- a/numpy/core/tests/test_longdouble.py +++ b/numpy/core/tests/test_longdouble.py @@ -70,6 +70,19 @@ def test_fromstring(): err_msg="reading '%s'" % s) +def test_fromstring_complex(): + for ctypes in ["cdouble", "cfloat"]: + # Check spacing between separator + assert_equal(np.fromstring("1, 2 , 3 ,4",sep=",",dtype=ctypes), + np.array([1., 2., 3., 4.])) + # Real component not specified + assert_equal(np.fromstring("1j, -2j, 3j, 4e1j",sep=",",dtype=ctypes), + np.array([1.j, -2.j, 3.j, 40.j])) + # Both components specified + assert_equal(np.fromstring("1+1j,2-2j, -3+3j, -4e1", sep=",", dtype=ctypes), + np.array([1. + 1.j, 2. - 2.j, - 3. + 3.j, - 40.])) + + def test_fromstring_bogus(): assert_equal(np.fromstring("1. 2. 3. flop 4.", dtype=float, sep=" "), np.array([1., 2., 3.])) |