{"record":{"id":"2e7d56a02591ae8a","repo":"keras-team/keras","slug":"start-index-length-self-start-index-end-index","errorCode":null,"errorMessage":"`start_index+length={self.start_index} > end_index={self.end_index}` is disallowed, as no part of the sequence would be left to be used as current step.","messagePattern":"`start_index\\+length=(.+?) > end_index=(.+?)` is disallowed, as no part of the sequence would be left to be used as current step\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/legacy/preprocessing/sequence.py","lineNumber":93,"sourceCode":"                f\"of same length. Data length is {len(data)} \"\n                f\"while target length is {len(targets)}\"\n            )\n\n        self.data = data\n        self.targets = targets\n        self.length = length\n        self.sampling_rate = sampling_rate\n        self.stride = stride\n        self.start_index = start_index + length\n        if end_index is None:\n            end_index = len(data) - 1\n        self.end_index = end_index\n        self.shuffle = shuffle\n        self.reverse = reverse\n        self.batch_size = batch_size\n\n        if self.start_index > self.end_index:\n            raise ValueError(\n                f\"`start_index+length={self.start_index} \"\n                f\"> end_index={self.end_index}` \"\n                \"is disallowed, as no part of the sequence \"\n                \"would be left to be used as current step.\"\n            )\n\n    def __len__(self):\n        return (\n            self.end_index - self.start_index + self.batch_size * self.stride\n        ) // (self.batch_size * self.stride)\n\n    def __getitem__(self, index):\n        if self.shuffle:\n            rows = np.random.randint(\n                self.start_index, self.end_index + 1, size=self.batch_size\n            )\n        else:\n            i = self.start_index + self.batch_size * self.stride * index","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/legacy/preprocessing/sequence.py#L75-L111","documentation":"TimeseriesGenerator needs at least one usable timestep at or after start_index to serve as the 'current step' target, so start_index must not exceed end_index (normally end_index = len(data) - 1). The f-string even prints 'start_index+length' because that is the typical intended meaning. Violating it leaves no valid windows.","triggerScenarios":"Passing start_index greater than end_index, e.g. TimeseriesGenerator(data, targets, length=50, start_index=900, end_index=800), or a series so short that end_index collapses below start_index.","commonSituations":"Carving train/validation splits with explicit start_index/end_index and swapping the two; window length >= series length.","solutions":["Fix the split so start_index <= end_index, typically end_index = len(data) - 1","Ensure len(data) > length so at least one window fits","Compute indices programmatically instead of hardcoding them"],"exampleFix":"# before\nTimeseriesGenerator(data, targets, length=10, start_index=800, end_index=750)\n# after\nTimeseriesGenerator(data, targets, length=10, start_index=0, end_index=len(data) - 1)","handlingStrategy":"validation","validationCode":"end_index = min(end_index, len(data) - 1)\nif start_index > end_index:\n    raise ValueError('empty window range')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute end_index from len(data) instead of hardcoding","Check len(data) > length before constructing the generator"],"tags":["keras","timeseries","preprocessing","index-bounds"],"backgroundTag":"index-out-of-range","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}