{"record":{"id":"86d485fbb036eecb","repo":"keras-team/keras","slug":"if-class-mode-y-col-must-be-a-list-received","errorCode":null,"errorMessage":"If class_mode=\"{}\", y_col must be a list. Received {}.","messagePattern":"If class_mode=\"(.+?)\", y_col must be a list\\. Received (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"keras/src/legacy/preprocessing/image.py","lineNumber":805,"sourceCode":"                f\"belonging to {num_classes} classes.\"\n            )\n        self._filepaths = [\n            os.path.join(self.directory, fname) for fname in self.filenames\n        ]\n        super().__init__(self.samples, batch_size, shuffle, seed)\n\n    def _check_params(self, df, x_col, y_col, weight_col, classes):\n        # check class mode is one of the currently supported\n        if self.class_mode not in self.allowed_class_modes:\n            raise ValueError(\n                \"Invalid class_mode: {}; expected one of: {}\".format(\n                    self.class_mode, self.allowed_class_modes\n                )\n            )\n        # check that y_col has several column names if class_mode is\n        # multi_output\n        if (self.class_mode == \"multi_output\") and not isinstance(y_col, list):\n            raise TypeError(\n                'If class_mode=\"{}\", y_col must be a list. Received {}.'.format(\n                    self.class_mode, type(y_col).__name__\n                )\n            )\n        # check that filenames/filepaths column values are all strings\n        if not all(df[x_col].apply(lambda x: isinstance(x, str))):\n            raise TypeError(\n                f\"All values in column x_col={x_col} must be strings.\"\n            )\n        # check labels are string if class_mode is binary or sparse\n        if self.class_mode in {\"binary\", \"sparse\"}:\n            if not all(df[y_col].apply(lambda x: isinstance(x, str))):\n                raise TypeError(\n                    'If class_mode=\"{}\", y_col=\"{}\" column '\n                    \"values must be strings.\".format(self.class_mode, y_col)\n                )\n        # check that if binary there are only 2 different classes\n        if self.class_mode == \"binary\":","sourceCodeStart":787,"sourceCodeEnd":823,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/legacy/preprocessing/image.py#L787-L823","documentation":"With class_mode='multi_output', y_col must be a list of DataFrame column names so the iterator can yield a dict of targets per column. A single string is treated as one column and rejected.","triggerScenarios":"flow_from_dataframe(..., class_mode='multi_output', y_col='price').","commonSituations":"Migrating from single-output code and forgetting to wrap y_col in a list.","solutions":["Pass y_col as a list: y_col=['price','category']","Ensure each named column exists in the DataFrame"],"exampleFix":"// before\ny_col='price'\n// after\ny_col=['price', 'category']\n","handlingStrategy":"type-guard","validationCode":"if class_mode == 'multi_output': assert isinstance(y_col, list)","typeGuard":"def is_list(v): return isinstance(v, list)","tryCatchPattern":"try: flow_from_dataframe(..., y_col=y_col)\nexcept TypeError as e: if 'must be a list' in str(e): y_col = [y_col]","preventionTips":["Always wrap multi-output targets in lists"],"tags":["keras","dataframe","multi-output"],"backgroundTag":"invalid-argument-type","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}