Skip to content

Commit f3ea9b2

Browse files
committed
[NFC][DF] Add note about return statements in string expressions
1 parent d957c13 commit f3ea9b2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tree/dataframe/inc/ROOT/RDF/RInterface.hxx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ public:
282282
/// // String: it must contain valid C++ except that column names can be used instead of variable names
283283
/// auto filtered = df.Filter("x*y > 0");
284284
/// ~~~
285+
///
286+
/// \note If the body of the string expression contains an explicit `return` statement (even if it is in a nested
287+
/// scope), RDataFrame _will not_ add another one in front of the expression. So this will not work:
288+
/// ~~~{.cpp}
289+
/// df.Filter("Sum(Map(vec, [](float e) { return e*e > 0.5; }))")
290+
/// ~~~
291+
/// but instead this will:
292+
/// ~~~{.cpp}
293+
/// df.Filter("return Sum(Map(vec, [](float e) { return e*e > 0.5; }))")
294+
/// ~~~
285295
template <typename F, std::enable_if_t<!std::is_convertible<F, std::string>::value, int> = 0>
286296
RInterface<RDFDetail::RFilter<F, Proxied>, DS_t>
287297
Filter(F f, const ColumnNames_t &columns = {}, std::string_view name = "")
@@ -343,6 +353,16 @@ public:
343353
/// auto filtered_df = df.Filter("myCollection.size() > 3");
344354
/// auto filtered_name_df = df.Filter("myCollection.size() > 3", "Minumum collection size");
345355
/// ~~~
356+
///
357+
/// \note If the body of the string expression contains an explicit `return` statement (even if it is in a nested
358+
/// scope), RDataFrame _will not_ add another one in front of the expression. So this will not work:
359+
/// ~~~{.cpp}
360+
/// df.Filter("Sum(Map(vec, [](float e) { return e*e > 0.5; }))")
361+
/// ~~~
362+
/// but instead this will:
363+
/// ~~~{.cpp}
364+
/// df.Filter("return Sum(Map(vec, [](float e) { return e*e > 0.5; }))")
365+
/// ~~~
346366
RInterface<RDFDetail::RJittedFilter, DS_t> Filter(std::string_view expression, std::string_view name = "")
347367
{
348368
// deleted by the jitted call to JitFilterHelper
@@ -386,6 +406,16 @@ public:
386406
/// // alternatively, we can pass the body of the function as a string, as in Filter:
387407
/// auto df_with_define = df.Define("newColumn", "x*x + y*y");
388408
/// ~~~
409+
///
410+
/// \note If the body of the string expression contains an explicit `return` statement (even if it is in a nested
411+
/// scope), RDataFrame _will not_ add another one in front of the expression. So this will not work:
412+
/// ~~~{.cpp}
413+
/// df.Define("x2", "Map(v, [](float e) { return e*e; })")
414+
/// ~~~
415+
/// but instead this will:
416+
/// ~~~{.cpp}
417+
/// df.Define("x2", "return Map(v, [](float e) { return e*e; })")
418+
/// ~~~
389419
template <typename F, typename std::enable_if_t<!std::is_convertible<F, std::string>::value, int> = 0>
390420
RInterface<Proxied, DS_t> Define(std::string_view name, F expression, const ColumnNames_t &columns = {})
391421
{
@@ -463,6 +493,16 @@ public:
463493
/// It must be valid C++ syntax in which variable names are substituted with the names
464494
/// of branches/columns.
465495
///
496+
/// \note If the body of the string expression contains an explicit `return` statement (even if it is in a nested
497+
/// scope), RDataFrame _will not_ add another one in front of the expression. So this will not work:
498+
/// ~~~{.cpp}
499+
/// df.Define("x2", "Map(v, [](float e) { return e*e; })")
500+
/// ~~~
501+
/// but instead this will:
502+
/// ~~~{.cpp}
503+
/// df.Define("x2", "return Map(v, [](float e) { return e*e; })")
504+
/// ~~~
505+
///
466506
/// Refer to the first overload of this method for the full documentation.
467507
RInterface<Proxied, DS_t> Define(std::string_view name, std::string_view expression)
468508
{

0 commit comments

Comments
 (0)