diff options
author | Matti Picus <matti.picus@gmail.com> | 2019-10-31 08:47:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-31 08:47:44 +0200 |
commit | c03ce145cc991e1873b1595a128825992300d97a (patch) | |
tree | 4f37ecf6faf8528727e97222b7c81628f58d509d /numpy/core/tests | |
parent | c1d9eec58bd83257c4cb69b82308c7263d31a3e9 (diff) | |
parent | 880acfeba83309607908249fc6dcdf83c8fe410a (diff) | |
download | numpy-c03ce145cc991e1873b1595a128825992300d97a.tar.gz |
Merge pull request #14227 from zjpoh/from_string_complex
ENH: Parse complex number from string
Diffstat (limited to 'numpy/core/tests')
-rw-r--r-- | numpy/core/tests/test_longdouble.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/numpy/core/tests/test_longdouble.py b/numpy/core/tests/test_longdouble.py index c8fac86ff..2b6e1c5a2 100644 --- a/numpy/core/tests/test_longdouble.py +++ b/numpy/core/tests/test_longdouble.py @@ -71,6 +71,38 @@ def test_fromstring(): err_msg="reading '%s'" % s) +def test_fromstring_complex(): + for ctype in ["complex", "cdouble", "cfloat"]: + # Check spacing between separator + assert_equal(np.fromstring("1, 2 , 3 ,4", sep=",", dtype=ctype), + np.array([1., 2., 3., 4.])) + # Real component not specified + assert_equal(np.fromstring("1j, -2j, 3j, 4e1j", sep=",", dtype=ctype), + np.array([1.j, -2.j, 3.j, 40.j])) + # Both components specified + assert_equal(np.fromstring("1+1j,2-2j, -3+3j, -4e1+4j", sep=",", dtype=ctype), + np.array([1. + 1.j, 2. - 2.j, - 3. + 3.j, - 40. + 4j])) + # Spaces at wrong places + with assert_warns(DeprecationWarning): + assert_equal(np.fromstring("1+2 j,3", dtype=ctype, sep=","), + np.array([1.])) + with assert_warns(DeprecationWarning): + assert_equal(np.fromstring("1+ 2j,3", dtype=ctype, sep=","), + np.array([1.])) + with assert_warns(DeprecationWarning): + assert_equal(np.fromstring("1 +2j,3", dtype=ctype, sep=","), + np.array([1.])) + with assert_warns(DeprecationWarning): + assert_equal(np.fromstring("1+j", dtype=ctype, sep=","), + np.array([1.])) + with assert_warns(DeprecationWarning): + assert_equal(np.fromstring("1+", dtype=ctype, sep=","), + np.array([1.])) + with assert_warns(DeprecationWarning): + assert_equal(np.fromstring("1j+1", dtype=ctype, sep=","), + np.array([1j])) + + def test_fromstring_bogus(): with assert_warns(DeprecationWarning): assert_equal(np.fromstring("1. 2. 3. flop 4.", dtype=float, sep=" "), |