Skip to content

(RDataFrame) AsNumpy returns Boolean branches as 'object' dtype numpy arrays #8639

@ryuwd

Description

@ryuwd

Explain what you would like to see improved

Reading a TTree with boolean branches using ROOT.RDataFrame .AsNumpy(...) will return numpy arrays for those branches, where the dtype for the numpy arrays corresponding to the boolean branches have dtype object, not bool.

Optional: share how it could be improved

The dtype for numpy arrays created from boolean branches should have the bool dtype.

To Reproduce

>>> import ROOT
>>> rdf = ROOT.RDataFrame(100).Define("bool_branch", "(int)rdfentry_ > 50").AsNumpy(["bool_branch"])
>>> rdf
{'bool_branch': ndarray([False, False, False, False, False, False, False, False, False,
         False, False, False, False, False, False, False, False, False,
         False, False, False, False, False, False, False, False, False,
         False, False, False, False, False, False, False, False, False,
         False, False, False, False, False, False, False, False, False,
         False, False, False, False, False, False, True, True, True, True,
         True, True, True, True, True, True, True, True, True, True, True,
         True, True, True, True, True, True, True, True, True, True, True,
         True, True, True, True, True, True, True, True, True, True, True,
         True, True, True, True, True, True, True, True, True, True, True,
         True], dtype=object)}

Setup

Conda:

  - root=6.24.0=py39hde0f152_0
  - root_base=6.24.0=py39h9c0239e_0
   ------------------------------------------------------------------
  | Welcome to ROOT 6.24/00                        https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Apr 20 2021, 16:07:00                 |
  | From tag , 14 April 2021                                         |
  | With                                                             |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

Operating system (running inside singularity)

(/conda_prefix/4579f7cd229dff884e79648a22bf1fbc) Singularity> cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.10
DISTRIB_CODENAME=groovy
DISTRIB_DESCRIPTION="Ubuntu 20.10"

Additional context

I also reproduced the issue on macos.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions