{"record":{"id":"e5aaa4bc89c77d5c","repo":"pandas-dev/pandas","slug":"cannot-multiply-with-type-other-name","errorCode":null,"errorMessage":"Cannot multiply with {type(other).__name__}","messagePattern":"Cannot multiply with (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/timedeltas.py","lineNumber":555,"sourceCode":"                    # The extreme elements bound all products, so checking them\n                    #  with exact Python-int arithmetic lets the common\n                    #  no-overflow case use a vectorized multiply. NaT\n                    #  (int64.min) always trips the bound, falling through to\n                    #  the NaT-aware cython loop.\n                    low_prod = int(i8_vals.min()) * other\n                    high_prod = int(i8_vals.max()) * other\n                    if max(abs(low_prod), abs(high_prod)) <= lib.i8max:\n                        result = (i8_vals * other).view(self._ndarray.dtype)\n                        return type(self)._simple_new(result, dtype=result.dtype)\n                return self._mul_int_overflowsafe(np.asarray(other, dtype=\"i8\"))\n            if lib.is_float(other):\n                return self._mul_float_overflowsafe(other)\n            # numpy will raise TypeError for non-numeric scalar\n            result = self._ndarray * other\n            if result.dtype.kind != \"m\":\n                # numpy >= 2.1 may not raise a TypeError\n                # and seems to dispatch to others.__rmul__?\n                raise TypeError(f\"Cannot multiply with {type(other).__name__}\")\n            return type(self)._simple_new(result, dtype=result.dtype)\n\n        if not hasattr(other, \"dtype\"):\n            # list, tuple\n            other = np.array(other)\n\n        if other.dtype.kind == \"b\":\n            # GH#58054\n            raise TypeError(\n                f\"Cannot multiply '{self.dtype}' by bool, explicitly cast to \"\n                \"integers instead\"\n            )\n        if isinstance(other.dtype, (ArrowDtype, BaseMaskedDtype)):\n            # GH#58054\n            return NotImplemented\n\n        if len(other) != len(self) and not lib.is_np_dtype(other.dtype, \"m\"):\n            # Exclude timedelta64 here so we correctly raise TypeError","sourceCodeStart":537,"sourceCodeEnd":573,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/timedeltas.py#L537-L573","documentation":"Raised in TimedeltaArray.__mul__ for a scalar operand that is not bool/int/float and where numpy (>=2.1) neither raised a TypeError nor produced a timedelta64 result. Since numpy 2.1 may dispatch to other.__rmul__ instead of erroring, pandas inspects the result dtype: if it is not timedelta-like ('m'), it raises TypeError naming the offending type.","triggerScenarios":"Multiplying a timedelta64 array by an unsupported scalar type (e.g. a string, complex, Decimal, or custom numeric) where numpy 2.1+ does not itself raise.","commonSituations":"Passing arbitrary objects or third-party numeric types (Decimal, sympy numbers) as timedelta multipliers; numpy version changes that altered dispatch behavior.","solutions":["Convert the operand to a plain int or float before multiplying.","If you genuinely need custom-numeric scaling, perform the arithmetic in a numeric space (total_seconds) and reconstruct the timedelta.","Pin/verify numpy < 2.1 only if you cannot change the operand type — but fixing the operand is preferred."],"exampleFix":"# before\nfrom decimal import Decimal\npd.to_timedelta([1, 2], unit='D') * Decimal('2')  # TypeError\n\n# after\npd.to_timedelta([1, 2], unit='D') * float(Decimal('2'))","handlingStrategy":"type-guard","validationCode":"import numbers\nimport numpy as np\n\ndef as_td_scalar_multiplier(x):\n    if isinstance(x, (bool, np.bool_)):\n        raise TypeError('bool not allowed')\n    if isinstance(x, (numbers.Integer, numbers.Real, np.integer, np.floating)):\n        return x\n    return float(x)","typeGuard":"import numbers, numpy as np\n\ndef is_supported_td_scalar(x) -> bool:\n    return isinstance(x, (numbers.Integer, numbers.Real, np.integer, np.floating)) and not isinstance(x, (bool, np.bool_))","tryCatchPattern":"try:\n    result = td * other\nexcept TypeError as e:\n    if 'Cannot multiply with' in str(e):\n        result = td * float(other)\n    else:\n        raise","preventionTips":["Coerce custom/Decimal numeric types to float/int before timedelta arithmetic.","Validate scalar operand types when accepting user-supplied multipliers."],"tags":["timedelta","multiplication","typeerror","numpy2","dtype"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}