Skip to content

[Python] pathlib: Improve compatibility with python #20482

@acampove

Description

@acampove

Check duplicate issues.

  • Checked for duplicates

Description

I see all over the place problems when I try to use ROOT with python. This time I see that there is no support for Path objects.

Reproducer

import ROOT
from pathlib import Path
import numpy as np

root_file = ROOT.TFile("example_data.root", "RECREATE")
tree      = ROOT.TTree("myTree", "Example Tree")

x = np.zeros(1, dtype=float)
y = np.zeros(1, dtype=float)
z = np.zeros(1, dtype=float)

tree.Branch("x", x, "x/D")
tree.Branch("y", y, "y/D")
tree.Branch("z", z, "z/D")

for i in range(10):
    x[0] = i
    y[0] = i * 2 + np.random.normal(0, 1)
    z[0] = x[0]**2 + y[0]
    tree.Fill()

tree.Write()
root_file.Close()

file_path = Path("example_data.root")

df = ROOT.RDataFrame("myTree", file_path)

ROOT version

6.36.04

Installation method

mamba

Operating system

almalinux 9

Additional context

Any good out there uses Path, not strings when handling paths.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions