Skip to content

[BUG] Failure to conver awkward Masked array to numpy #706

Open
@MoAly98

Description

@MoAly98

I have a masked awkward array that I am trying to pass to Hist.fill(). The inner conversion to numpy arrays seems to fail because the allow_missing flag in to_numpy() is set to False. From the error log, it seems that this is set to false by hard-coding somewhere in the AwkwardArray source code. However, I do not run into this problem if I simply call to_numpy() on my array before passing it to Hist.fill() -- i.e. doing the conversion explicitly. The following code re-produces the problem:

 arr2 = ak.Array([1,2,3,4])
arr2m = ak.mask(arr2, arr2>1)
>>> [None, 2, 3, 4]
import boost_histogram as bh
bh.axis.Regular(5,0,1)
>>> Regular(5, 0, 1)
ax = bh.axis.Regular(5,0,1)
histo = bh.Histogram(ax)
histo.fill(arr2m)
>>>
  File "<stdin>", line 1, in <module>
  File "/opt/anaconda3/envs/pythium/lib/python3.9/site-packages/boost_histogram/_internal/hist.py", line 467, in fill
    args_ars = _fill_cast(args)
  File "/opt/anaconda3/envs/pythium/lib/python3.9/site-packages/boost_histogram/_internal/hist.py", line 78, in _fill_cast
    return tuple(_fill_cast(a, inner=True) for a in value)  # type: ignore
  File "/opt/anaconda3/envs/pythium/lib/python3.9/site-packages/boost_histogram/_internal/hist.py", line 78, in <genexpr>
    return tuple(_fill_cast(a, inner=True) for a in value)  # type: ignore
  File "/opt/anaconda3/envs/pythium/lib/python3.9/site-packages/boost_histogram/_internal/hist.py", line 80, in _fill_cast
    return np.asarray(value)
  File "/opt/anaconda3/envs/pythium/lib/python3.9/site-packages/awkward/highlevel.py", line 1358, in __array__
    return ak._connect._numpy.convert_to_array(self.layout, args, kwargs)
  File "/opt/anaconda3/envs/pythium/lib/python3.9/site-packages/awkward/_connect/_numpy.py", line 15, in convert_to_array
    out = ak.operations.convert.to_numpy(layout, allow_missing=False)
  File "/opt/anaconda3/envs/pythium/lib/python3.9/site-packages/awkward/operations/convert.py", line 312, in to_numpy
    raise ValueError(
ValueError: ak.to_numpy cannot convert 'None' values to np.ma.MaskedArray unless the 'allow_missing' parameter is set to True

(https://github.com/scikit-hep/awkward-1.0/blob/1.7.0/src/awkward/operations/convert.py#L316)

As far as I can see, there is no option to set allow_missing = True in the fill() funciton call, so I wonder if this restriction is intentional or a bug?

Thank you very much.

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