10000 Python 3.7 can cast object to complex type · Issue #11993 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Python 3.7 can cast object to complex type #11993
Closed
@bear24rw

Description

@bear24rw

Reproducing code example:

import numpy as np
print(np.__version__)
arr = np.array(['AAAAA', 18465886.0, 18465886.0], dtype=object)
print(arr.astype(np.complex64))
print(arr.astype(np.complex64)) 

Error message:

Python3.6 works as I would expect (complains that it cannot convert a string to complex dtype)

$ python3.6 test.py 
1.16.0.dev0+7fcba41
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    print(arr.astype(np.complex64))
TypeError: must be real number, not str

Python3.7 converts it to a complex type and then errors if you try to do it again

$ python3.7 test.py 
1.16.0.dev0+7fcba41
[-6.3090155e-31+4.558e-41j  1.8465886e+07+0.000e+00j
  1.8465886e+07+0.000e+00j]
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    print(arr.astype(np.complex64)) 
TypeError: must be real number, not str

Numpy/Python version information:

>>> import sys
>>> sys.version
'3.7.0b3 (default, Mar 30 2018, 04:35:22) \n[GCC 7.3.0]'
>>> import numpy as np
>>> np.__version__
'1.16.0.dev0+7fcba41'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0