{"record":{"id":"e4852296b754f124","repo":"keras-team/keras","slug":"unsupported-data-type-type-data-adapt-suppo","errorCode":null,"errorMessage":"Unsupported data type: {type(data)}. `adapt` supports `np.ndarray`, backend tensors, `tf.data.Dataset`, `keras.utils.PyDataset`, and iterables of batches (e.g. list, generator).","messagePattern":"Unsupported data type: (.+?)\\. `adapt` supports `np\\.ndarray`, backend tensors, `tf\\.data\\.Dataset`, `keras\\.utils\\.PyDataset`, and iterables of batches \\(e\\.g\\. list, generator\\)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/normalization.py","lineNumber":320,"sourceCode":"                    \"adapt() received an empty iterable (no batches). \"\n                    \"Expected at least one batch. Pass a non-empty iterable \"\n                    \"of arrays or tensors, e.g. layer.adapt([x]) or \"\n                    \"layer.adapt(list_of_batches).\"\n                )\n            first_batch = _extract_batch(first_batch)\n            input_shape = getattr(first_batch, \"shape\", None)\n            if input_shape is None:\n                raise TypeError(\n                    \"adapt() expects an iterable that yields arrays or \"\n                    \"tensors with a `.shape` attribute (e.g. numpy arrays or \"\n                    \"backend tensors). Got an element of type \"\n                    f\"{type(first_batch).__name__}. Ensure each yielded \"\n                    \"element is array-like with a `.shape` attribute.\"\n                )\n            input_shape = tuple(input_shape)\n            data = itertools.chain([first_batch], data_iter)\n        else:\n            raise TypeError(\n                f\"Unsupported data type: {type(data)}. `adapt` supports \"\n                f\"`np.ndarray`, backend tensors, `tf.data.Dataset`, \"\n                f\"`keras.utils.PyDataset`, and iterables of batches (e.g. \"\n                f\"list, generator).\"\n            )\n\n        if not self.built:\n            self.build(input_shape)\n        else:\n            for d in self._keep_axis:\n                if input_shape[d] != self._build_input_shape[d]:\n                    raise ValueError(\n                        \"The layer was built with \"\n                        f\"input_shape={self._build_input_shape}, \"\n                        \"but adapt() is being called with data with \"\n                        f\"an incompatible shape, data.shape={input_shape}\"\n                    )\n","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/normalization.py#L302-L338","documentation":"Normalization.adapt() only accepts np.ndarray, backend tensors, tf.data.Dataset, PyDataset, or iterables of batches. Anything else (int, str path, callable) hits the final else-branch and raises a TypeError enumerating the supported types.","triggerScenarios":"layer.adapt(5), adapt('path/to/file.csv'), adapt(some_function), or passing an object without __iter__ that is not one of the recognized dataset types.","commonSituations":"Passing a path expecting adapt to load it; passing a scikit-learn Dataset-like object; typos where a variable holding a filename is adapted.","solutions":["Load the data first, then adapt: layer.adapt(np.loadtxt(path, delimiter=','))","Wrap sequences: layer.adapt(list_of_batches)","Convert containers: layer.adapt(df['col'].to_numpy()) instead of raw non-array objects"],"exampleFix":"// before\nlayer.adapt('train.csv')\n// after\nimport numpy as np\nlayer.adapt(np.loadtxt('train.csv', delimiter=','))","handlingStrategy":"type-guard","validationCode":"def adapt_ready(d):\n    return hasattr(d, 'shape') or hasattr(d, '__iter__')\nassert adapt_ready(data), 'pass arrays, datasets, or iterables of batches'","typeGuard":"def supported_adapt_input(d):\n    return hasattr(d, 'shape') or hasattr(d, '__iter__')","tryCatchPattern":null,"preventionTips":["Load files to arrays before adapt","Never pass paths, ints, or callables"],"tags":["keras","normalization","adapt","type-validation"],"backgroundTag":"unsupported-input-type","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}