I cannot figure out how to set the fill_value of a real masked array to be np.nan. The array is the result of the calculation of two complex maskedarrays. Somehow, the calculated array's fill_value always gets converted to a complex fill_value, when I want a real fill_value. Even if I explicitly set the fill_value, it won't get set to a float. This is triggering ComplexWarnings in my code because it drops the imaginary part later. I am OK with setting the ang.fill_value manually, but it doesn't work.
import numpy as np
ma1 = np.ma.MaskedArray([1.1+1j, 2.2-1j])
ma2 = np.ma.MaskedArray([2.2+1j, 3.3+1j])
ma1.fill_value = np.nan + np.nan*1j
ma2.fill_value = np.nan + np.nan*1j
ang = np.ma.angle(ma1/ma2, deg=True)
ang.fill_value = np.nan
print(ang.fill_value)
<prints out (nan+0j)>
First, I haven't worked with
angle(maor not), and only played withnp.maon and off, mainly for SO questions.np.angleis python code;np.ma.angleis produced by a generic wrapper onnp.angle.Without studying those, let's experiement.
Your array ratio:
The non-ma version:
or
The angle:
The data dtype looks fine, but the fill dtype is complex. Without
ma, it's still masked, but with a different fill, and a simple mask:If we give it the "raw" data:
np.mais not heavily used, so I'm not surprised that there are bugs in details like this, passing the fill and mask through. Especially in a function like this that can take a complex argument, but returns a real result.If I don't fiddle with the fill values,
The angle fill is float.
Casting
(nan+nanj)to float might be producing some errors or warnings that it doesn't get with(1e+20+0j). Again we'd have to examine the code.