{"record":{"id":"92dcc064871424b3","repo":"deezer/spleeter","slug":"n-chunks-per-song-must-be-positif","errorCode":null,"errorMessage":"n_chunks_per_song must be positif","messagePattern":"n_chunks_per_song must be positif","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"spleeter/dataset.py","lineNumber":433,"sourceCode":"        }\n        return (input_, output)\n\n    def compute_segments(self, dataset: Any, n_chunks_per_song: int) -> Any:\n        \"\"\"\n        Computes segments for each song of the dataset.\n\n        Parameters:\n            dataset (Any):\n                Dataset to compute segments for.\n            n_chunks_per_song (int):\n                Number of segment per song to compute.\n\n        Returns:\n            Any:\n                Segmented dataset.\n        \"\"\"\n        if n_chunks_per_song <= 0:\n            raise ValueError(\"n_chunks_per_song must be positif\")\n        datasets = []\n        for k in range(n_chunks_per_song):\n            if n_chunks_per_song > 1:\n                datasets.append(\n                    dataset.map(\n                        lambda sample: dict(\n                            sample,\n                            start=tf.maximum(\n                                k\n                                * (\n                                    sample[\"duration\"]\n                                    - self._chunk_duration\n                                    - 2 * self.MARGIN\n                                )\n                                / (n_chunks_per_song - 1)\n                                + self.MARGIN,\n                                0,\n                            ),","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/deezer/spleeter/blob/c8854001ac8acad34a9bc2bd15f28475541828b1/spleeter/dataset.py#L415-L451","documentation":"compute_segments validates n_chunks_per_song before slicing a dataset into per-song chunk datasets. If the value is zero or negative, there would be zero map iterations and no meaningful segmentation, so it raises ValueError immediately. Note the message contains a typo ('positif'), which is how you can identify this exact check.","triggerScenarios":"Calling compute_segments (directly or via the public build/entry API) with n_chunks_per_song=0 or a negative integer, e.g. from a miscomputed parameter or a config file where the chunk count was set to 0.","commonSituations":"Config files or CLI flags where the chunk count was computed by another expression that yielded 0; users assuming 0 means 'no chunking' when the API actually requires >= 1.","solutions":["Pass a positive integer for n_chunks_per_song (>= 1)","If you want no chunking, call compute_segments with n_chunks_per_song=1 rather than 0","Validate/normalize the value at config-load time: max(1, int(n_chunks_per_song))","Check upstream code that computes the value for off-by-one or empty-input bugs"],"exampleFix":"// before\ncompute_segments(dataset, n_chunks_per_song=0)\n// after\ncompute_segments(dataset, n_chunks_per_song=1)","handlingStrategy":"validation","validationCode":"def assert_positive_chunks(n):\n    if not isinstance(n, int) or n <= 0:\n        raise ValueError(f\"n_chunks_per_song must be a positive int, got {n!r}\")\n    return n\n\nassert_positive_chunks(n_chunks_per_song)  # call before compute_segments","typeGuard":"def is_positive_int(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool) and v > 0","tryCatchPattern":"try:\n    segments = compute_segments(dataset, n_chunks_per_song=n)\nexcept ValueError as e:\n    if 'n_chunks_per_song' in str(e):\n        logging.warning(\"Invalid n_chunks_per_song=%s, falling back to 1\", n)\n        segments = compute_segments(dataset, n_chunks_per_song=1)\n    else:\n        raise","preventionTips":["Clamp config values with max(1, int(value)) at load time","Use type-checked config parsing (pydantic/dataclass with PositiveInt)","Remember 0 does not mean 'disable chunking' — use 1 instead","Unit-test config parsing for chunk-count edge cases"],"tags":["python","valueerror","parameter-validation","spleeter"],"backgroundTag":"invalid-parameter-value","analyzedSha":"c8854001ac8acad34a9bc2bd15f28475541828b1","analyzedAt":"2026-08-28T21:38:40.142Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}