Skip to content

Commit

Permalink
[df] Check for empty file list in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
vepadulano authored and dpiparo committed Nov 16, 2024
1 parent fce7be7 commit bfa0b18
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tree/dataframe/src/RLoopManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,8 @@ std::shared_ptr<ROOT::Detail::RDF::RLoopManager>
ROOT::Detail::RDF::CreateLMFromTTree(std::string_view datasetName, const std::vector<std::string> &fileNameGlobs,
const std::vector<std::string> &defaultColumns, bool checkFile)
{
if (fileNameGlobs.size() == 0)
throw std::invalid_argument("RDataFrame: empty list of input files.");
// Introduce the same behaviour as in CreateLMFromFile for consistency.
// Creating an RDataFrame with a non-existing file will throw early rather
// than wait for the start of the graph execution.
Expand Down Expand Up @@ -1288,6 +1290,9 @@ ROOT::Detail::RDF::CreateLMFromFile(std::string_view datasetName, const std::vec
const ROOT::RDF::ColumnNames_t &defaultColumns)
{

if (fileNameGlobs.size() == 0)
throw std::invalid_argument("RDataFrame: empty list of input files.");

auto inFile = OpenFileWithSanityChecks(fileNameGlobs[0]);

if (inFile->Get<TTree>(datasetName.data())) {
Expand Down
10 changes: 10 additions & 0 deletions tree/dataframe/test/dataframe_regression.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,16 @@ TEST_P(RDFRegressionTests, FileNameQueryNoExt)
EXPECT_EQ(df.Count().GetValue(), 10);
}

TEST_P(RDFRegressionTests, EmptyFileList)
{
try {
ROOT::RDataFrame df{"", {}};
} catch (const std::invalid_argument &e) {
const std::string expected{"RDataFrame: empty list of input files."};
EXPECT_EQ(e.what(), expected);
}
}

// run single-thread tests
INSTANTIATE_TEST_SUITE_P(Seq, RDFRegressionTests, ::testing::Values(false));

Expand Down

0 comments on commit bfa0b18

Please sign in to comment.