Fix astype from complex to other types
@@ -349,6 +349,13 @@ cdef class ndarray:
newarray._set_shape_and_strides(self._shape, strides)
else:
newarray = ndarray(self.shape, dtype=dtype, order=order)
+
+ if self.dtype.kind == 'c' and newarray.dtype.kind != 'c':
+ warnings.warn(
+ 'Casting complex values to real discards the imaginary part',
+ numpy.ComplexWarning)
+ elementwise_copy(self.real, newarray)
+ else:
elementwise_copy(self, newarray)
return newarray
