[PyROOT][DF] `AsNumpy` automatically converts to numpy arrays
This Pull request:
Changes or fixes:
Calling AsNumpy on a dataframe (python api) now read RVec entries and std::vector as numpy.ndarray of the corresponding type. The implementation should be practically free besides some type checking.
It's not inmediate where to draw the line between what to convert into a numpy.ndarray. An RVec is clear but I also chose to convert std::vector, but not things such as std::array. Maybe std::vector shouldn't be converted. I haven't updated all the tests related to the conversion of std::vector so they are currently failing (I would like to have official confirmation).
We could also return a 2D (or N-D) regular array in the case the data is regular. This can be checked also without much overhead and the transformation into a regular array can be done via numpy.stack. From the offline discussions we decided that we would leave this final optional step to the user.
There are some consequences of these changes: for instance when dealing with string data, if we have a vector of strings of different length, it won't be converted into a numpy array. We could optionaly check for this and return a numpy array of objects. (there is a deprecation warning when you try to make an array from jagged data). In the case where all strings are the same length, the output of np.asarray is to convert them into multidimensional arrays of chars, which may not agree with what the user is expecting. Perhaps we could handle the std::string case separately but in this case what other cases should we handle separately?
Checklist:
- [x] tested changes locally
- [ ] updated the docs (if necessary)
This PR fixes https://github.com/root-project/root/issues/7685
Can one of the admins verify this patch?
@phsft-bot build
Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds
Build failed on ROOT-ubuntu2004/python3. Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build See console output.
Failing tests:
Build failed on ROOT-ubuntu2204/nortcxxmod. Running on root-ubuntu-2204-2.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build See console output.
Failing tests:
Build failed on ROOT-performance-centos8-multicore/soversion. Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build See console output.
Failing tests:
Build failed on mac12arm/cxx20. Running on 194.12.161.128:/Users/sftnight/build/workspace/root-pullrequests-build See console output.
Failing tests:
Test Results
9 files 9 suites 1d 17h 39m 7s :stopwatch: 2 537 tests 2 535 :white_check_mark: 0 :zzz: 2 :x: 21 731 runs 21 716 :white_check_mark: 0 :zzz: 15 :x:
For more details on these failures, see this check.
Results for commit f547ee12.