Commit f369ced
committed
[df] Allow reading a char column into a numpy array
In the AsNumpy operation values of the dataset are read into a ROOT::RVec
collection of the corresponding column type. Subsequently, the raw data is
accessed from the RVec and used to generate the array interface for a numpy
array view on the collected data.
When the column is of type char, and thus RDF would read values into a
ROOT::RVec<char>, the raw data is accessed as a 'char *'. The Python bindings
automatically convert 'char *' and 'const char *' to Python strings for full
compatibility with existing functions (e.g. otherwise TObject::GetName would not
return a string in Python). Thus, the array interface cannot be generated.
This commit proposes to introduce a special behaviour in AsNumpy to
automatically view the char column as an 'unsigned char' column. This in turn
will not incur in the automatic conversion on the Python side. An array of
'unsigned char' is interpreted as a numpy array with dtype uint8.
Since this is a decision which might be unexpected to some users, the commit
also proposes to let the user know about it via a warning.1 parent 283b12f commit f369ced
3 files changed
Lines changed: 44 additions & 4 deletions
File tree
- bindings/pyroot/pythonizations
- python/ROOT/_pythonization
- test
- tree/dataframe/src
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
| 232 | + | |
232 | 233 | | |
233 | 234 | | |
234 | 235 | | |
| |||
296 | 297 | | |
297 | 298 | | |
298 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
299 | 309 | | |
300 | 310 | | |
301 | 311 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
403 | 423 | | |
404 | 424 | | |
405 | 425 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
513 | 513 | | |
514 | 514 | | |
515 | 515 | | |
516 | | - | |
517 | | - | |
518 | | - | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
519 | 529 | | |
520 | 530 | | |
521 | 531 | | |
| |||
0 commit comments