{"record":{"id":"409e9af784284001","repo":"keras-team/keras","slug":"expected-an-integer-value-for-size-got-type-si","errorCode":null,"errorMessage":"Expected an integer value for `size`, got {type(size)}.","messagePattern":"Expected an integer value for `size`, got (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/reshaping/up_sampling1d.py","lineNumber":46,"sourceCode":"     [[ 6.  7.  8.]\n      [ 6.  7.  8.]\n      [ 9. 10. 11.]\n      [ 9. 10. 11.]]]\n\n    Args:\n        size: Integer. Upsampling factor.\n\n    Input shape:\n        3D tensor with shape: `(batch_size, steps, features)`.\n\n    Output shape:\n        3D tensor with shape: `(batch_size, upsampled_steps, features)`.\n    \"\"\"\n\n    def __init__(self, size=2, **kwargs):\n        super().__init__(**kwargs)\n        if not isinstance(size, int) or isinstance(size, bool):\n            raise TypeError(\n                f\"Expected an integer value for `size`, got {type(size)}.\"\n            )\n        if size <= 0:\n            raise ValueError(\n                \"Argument `size` should be a positive integer. \"\n                f\"Received: size={size}\"\n            )\n        self.size = size\n        self.input_spec = InputSpec(ndim=3)\n\n    def compute_output_shape(self, input_shape):\n        size = (\n            self.size * input_shape[1] if input_shape[1] is not None else None\n        )\n        return [input_shape[0], size, input_shape[2]]\n\n    def call(self, inputs):\n        return ops.repeat(x=inputs, repeats=self.size, axis=1)","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/reshaping/up_sampling1d.py#L28-L64","documentation":"UpSampling1D.__init__ requires size to be a real Python int (bools explicitly rejected because bool subclasses int). Floats, strings and None raise this TypeError at layer construction.","triggerScenarios":"UpSampling1D(size=2.0), UpSampling1D(size='2'), UpSampling1D(size=None), or UpSampling1D(size=True). Raised before any input is seen.","commonSituations":"Config files (YAML/JSON) yielding floats like 2.0; hyperparameter tuners returning continuous values that should be integers; copying size from a variable typed as float.","solutions":["Cast at construction: UpSampling1D(size=int(size))","Make the config source emit an integer (type the field as int in the schema)","If a tuner proposes the value, round and cast in the objective function"],"exampleFix":"# before\nsize = cfg.get('upsample', 2.0)\nlayer = UpSampling1D(size=size)  # TypeError\n\n# after\nsize = int(cfg.get('upsample', 2))\nlayer = UpSampling1D(size=size)","handlingStrategy":"type-guard","validationCode":"def coerce_size(size):\n    if not (isinstance(size, int) and not isinstance(size, bool)):\n        raise TypeError(f'size must be int, got {type(size)}')\n    return size","typeGuard":"def is_strict_int(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool)","tryCatchPattern":null,"preventionTips":["Type upsample factors as int in config schemas","Cast tuner outputs with int(round(x))","Never pass size=None; omit the arg to use the default 2"],"tags":["keras","upsampling1d","type-validation","argument-validation"],"backgroundTag":"wrong-argument-type","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}