{"record":{"id":"b29339262cba50c6","repo":"stanfordnlp/CoreNLP","slug":"illegal-request-for-fold-fold-of-numfolds-on","errorCode":null,"errorMessage":"Illegal request for fold ${fold} of ${numFolds} on data set of size ${size}","messagePattern":"Illegal request for fold (.+?) of (.+?) on data set of size (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/classify/GeneralDataset.java","lineNumber":290,"sourceCode":"   *  @param fractionSplit The first fractionSplit of datums (rounded down) will be the second split\n   *  @return A Pair of data sets, the first being the remainder of size ceiling(this.size() * (1-p)) drawn\n   *          from the end of the dataset and the second of size floor(this.size() * p) drawn from the\n   *          start of the dataset.\n   */\n  public abstract Pair<GeneralDataset<L, F>, GeneralDataset<L, F>> split (double fractionSplit);\n\n  /** Divide out a (devtest) split of the dataset versus the rest of it (as a training set).\n   *\n   *  @param fold The number of this fold (must be between 0 and (numFolds - 1)\n   *  @param numFolds The number of folds to divide the data into (must be greater than or equal to the\n   *                  size of the data set)\n   *  @return A Pair of data sets, the first being roughly (numFolds-1)/numFolds of the data items\n   *         (for use as training data_, and the second being 1/numFolds of the data, taken from the\n   *         fold<sup>th</sup> part of the data (for use as devTest data)\n   */\n  public Pair<GeneralDataset<L, F>, GeneralDataset<L, F>> splitOutFold(int fold, int numFolds) {\n    if (numFolds < 2 || numFolds > size() || fold < 0 || fold >= numFolds) {\n      throw new IllegalArgumentException(\"Illegal request for fold \" + fold + \" of \" + numFolds +\n              \" on data set of size \" + size());\n    }\n    int normalFoldSize = size()/numFolds;\n    int start = normalFoldSize * fold;\n    int end = start + normalFoldSize;\n    if (fold == (numFolds - 1)) {\n      end = size();\n    }\n    return split(start, end);\n  }\n\n  /**\n   * Returns the number of examples ({@link Datum}s) in the Dataset.\n   */\n  public int size() {\n    return size;\n  }\n","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/classify/GeneralDataset.java#L272-L308","documentation":"Thrown by GeneralDataset.splitOutFold when the requested fold index is out of the valid range [0, numFolds) for a data set of the given size. It is a range-validation guard protecting k-fold partitioning from bad fold arguments.","triggerScenarios":"Thrown at src/edu/stanford/nlp/classify/GeneralDataset.java:290 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use fold indices in 0..numFolds-1","Verify numFolds matches the value used to create the cross-validation iterator","Clamp or wrap fold indices before calling splitOutFold"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}