ROOT Version: 6.34.04
Platform: macOS Sequoia 15.4.1
Compiler: Unknown, from conda
How do I access to or rename a bad column name in an existing RDataFrame? Here is an example of a bad CSV title, “Current[A]”. Of course I can edit the original file but I would like to know a proper way.
In [1]: import ROOT
In [2]: df = ROOT.RDF.FromCSV('data/20250527_151152_HgAg_PDc_0.csv')
In [3]: df.GetColumnNames()
Out[3]:
vector<string>{ "CurrentActualWavelength", "CurrentNominalWavelength", "Current[A]", "Temp_AirAroundGrating", "Temp_AirAroundPD", "Temp_HgArLightSourceCabinet", "Temp_KEITHLEY6487Cabinet", "Temp_PDSM1Tube", "Time[s] (start=1748326329.7681952)
", "Wavelength[nm]" }
In [4]: df.Define('current', 'Current[A]')
input_line_58:2:21: error: use of undeclared identifier 'Current'
auto func0(){return Current[A]
^
input_line_58:2:29: error: use of undeclared identifier 'A'
auto func0(){return Current[A]
^
libc++abi: terminating due to uncaught exception of type std::runtime_error:
RDataFrame: An error occurred during just-in-time compilation. The lines above might indicate the cause of the crash
All RDF objects that have not run an event loop yet should be considered in an invalid state.
*** Break *** abort
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libcppyy_backend.6.34.04.so] (anonymous namespace)::TExceptionHandlerImp::HandleException(int) (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libCore.6.34.04.so] TUnixSystem::DispatchSignals(ESignals) (no debug info)
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[/usr/lib/system/libsystem_pthread.dylib] pthread_kill (no debug info)
[/usr/lib/system/libsystem_c.dylib] abort (no debug info)
[/usr/lib/libc++abi.dylib] __cxxabiv1::__aligned_malloc_with_fallback(unsigned long) (no debug info)
[/usr/lib/libc++abi.dylib] demangling_terminate_handler() (no debug info)
[/usr/lib/libobjc.A.dylib] _objc_terminate() (no debug info)
[/usr/lib/libc++abi.dylib] std::__terminate(void (*)()) (no debug info)
[/usr/lib/libc++abi.dylib] __cxa_get_exception_ptr (no debug info)
[/usr/lib/libc++abi.dylib] __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libROOTDataFrame.6.34.04.so] ROOT::Internal::RDF::InterpreterDeclare(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libROOTDataFrame.6.34.04.so] (anonymous namespace)::DeclareFunction(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&) (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libROOTDataFrame.6.34.04.so] ROOT::Internal::RDF::BookDefineJit(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::basic_string_view<char, std::__1::char_traits<char>>, ROOT::Detail::RDF::RLoopManager&, ROOT::RDF::RDataSource*, ROOT::Internal::RDF::RColumnRegister const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&, std::__1::shared_ptr<ROOT::Detail::RDF::RNodeBase>*) (no debug info)
[<unknown binary>] (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libcppyy_backend.6.34.04.so] WrapperCall(long, unsigned long, void*, void*, void*) (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libcppyy_backend.6.34.04.so] Cppyy::CallO(long, void*, unsigned long, void*, unsigned long) (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libcppyy.6.34.04.so] CPyCppyy::(anonymous namespace)::InstanceExecutor::Execute(long, void*, CPyCppyy::CallContext*) (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libcppyy.6.34.04.so] CPyCppyy::CPPMethod::ExecuteFast(void*, long, CPyCppyy::CallContext*) (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libcppyy.6.34.04.so] CPyCppyy::CPPMethod::ExecuteProtected(void*, long, CPyCppyy::CallContext*) (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libcppyy.6.34.04.so] CPyCppyy::CPPMethod::Call(CPyCppyy::CPPInstance*&, _object* const*, unsigned long, _object*, CPyCppyy::CallContext*) (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libcppyy.6.34.04.so] CPyCppyy::(anonymous namespace)::mp_vectorcall(CPyCppyy::CPPOverload*, _object* const*, unsigned long, _object*) (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libcppyy.6.34.04.so] CPyCppyy::SelectAndForward(CPyCppyy::TemplateProxy*, CPyCppyy::CPPOverload*, _object* const*, unsigned long, _object*, bool, bool, unsigned long long, std::__1::vector<CPyCppyy::Utility::PyError_t, std::__1::allocator<CPyCppyy::Utility::PyError_t>>&) (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/lib/libcppyy.6.34.04.so] CPyCppyy::tpp_vectorcall(CPyCppyy::TemplateProxy*, _object* const*, unsigned long, _object*) (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] PyObject_Vectorcall (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] _PyEval_EvalFrameDefault (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] PyEval_EvalCode (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] builtin_exec (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] _PyEval_EvalFrameDefault (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] gen_send_ex2 (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] gen_send_ex (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] _PyEval_EvalFrameDefault (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] method_vectorcall (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] _PyVectorcall_Call (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] _PyEval_EvalFrameDefault (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] PyEval_EvalCode (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] run_mod (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] _PyRun_SimpleFileObject (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] _PyRun_AnyFileObject (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] Py_RunMain (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] pymain_main (no debug info)
[/Users/oxon/anaconda3_arm/envs/lab309/bin/python3.12] main (no debug info)
[/usr/lib/dyld] start (no debug info)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[4], line 1
----> 1 df.Define('current', 'Current[A]')
File ~/anaconda3_arm/envs/lab309/lib/python3.12/site-packages/ROOT/_pythonization/_rdf_pyz.py:372, in _PyDefine(rdf, col_name, callable_or_str, cols, extra_args)
369 raise TypeError(f"First argument of Define must be a valid string for the new column name. {type(col_name).__name__} is not a string.")
371 if isinstance(callable_or_str, str): # If string argument is passed. Invoke the Original Define.
--> 372 return rdf._OriginalDefine(col_name, callable_or_str)
374 if not callable(callable_or_str): # The 2st argument is either a string or a python callable.
375 raise TypeError(f"The second argument of a Define operation should be a callable. {type(callable_or_str).__name__} object is not callable.")
TypeError: Template method resolution failed:
ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void>::Define(string_view name, string_view expression) =>
AbortSignal: abort from C++; program state was reset
Failed to instantiate "Define(ROOT::RDataFrame&,std::string,std::string)"
Failed to instantiate "Define(ROOT::RDataFrame*,std::string,std::string)"
Failed to instantiate "Define(ROOT::RDataFrame,std::string,std::string)"