RDataFrame has no virtual destructor

ROOT Version: 6.26/10
Platform: Ubuntu 22
Compiler: gcc10
PyROOT (Python 3.10.6)

I received a warning when I tried to write a child class from ROOT::RDataFrame:

RuntimeWarning: class “ROOT::RDataFrame” has no virtual destructor
class MyDataFrame(ROOT.RDataFrame):

Here is a minimal code to reproduce the warning:

import ROOT
class MyDataFrame(ROOT.RDataFrame):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def define_gamma(self, name: str, speed_cm_per_ns: str):
        return (self
            .Define('beta', f'{speed_cm_per_ns} / 29.9792458')
            .Define(name, '1 / sqrt(1 - beta * beta)')

rdf = MyDataFrame('tree', 'example.root')
rdf = rdf.define_gamma('gamma', 'speed')


  1. Will this warning cause any potential errors such as memory leaks or unexpected crashes?
  2. Is there a way to properly “fix (hence suppress)” this warning without simply import warnings in Python, and ignore it?

Thank you.

Hello @Fanurs!

As you can see from there not being a virtual destructor, the RDataFrame is not meant to be inherited from, so what you are trying to do there is a very bad idea.

You could follow the “composition over inheritance” idiom (which is generally a good idea), and create your custom wrapper class around RDataFrame instead.

If you just want to add a few functions to it, you can also make use of Pythons dynamic magic to add functions to a class like described here for example:
Dynamically add member function to an instance of a class in Python - Stack Overflow (in the final answer)

You can write your own module that patches ROOT as you wish.

As you see, with Python you can be very creative in solving your problems, but pls don’t inherit from RDataFrame :slight_smile:

If you have more questions, feel free to follow up here.



This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.