{"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":536,"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":518,"sourceCodeEnd":554,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/timedeltas.py#L518-L554","documentation":"Raised by TimedeltaArray.__mul__ when 'other' is a scalar that numpy accepted but produced a non-timedelta result dtype (the multiply did not yield timedelta64[ns]). This is the fallback TypeError after the int and float scalar branches are exhausted, guarding against nonsensical scalar multipliers. It exists because numpy >= 2.1 stopped raising TypeError in some cases and instead dispatched to other.__rmul__, so pandas re-asserts the result must stay timedelta-typed.","triggerScenarios":"Multiplying a Timedelta/Index of dtype timedelta64[ns] by an unsupported scalar type, e.g. `pd.Timedelta('1d') * pd.Timestamp('2020-01-01')` or a timedelta array times a string/decimal/object scalar. Hit only when other is a scalar that is neither Python int/float nor a recognized timedelta scalar, and numpy's `self._ndarray * other` returns a non-'m' dtype.","commonSituations":"Mixing timedelta with datetime objects, strings, Decimal, or custom numeric-like objects in vectorized ops; refactors that pass through untyped user input to arithmetic; version upgrades to numpy >= 2.1 where dispatch behavior changed.","solutions":["Inspect type(other); only multiply timedeltas by int or float scalars.","If you intended scaling time, convert other to int/float first (e.g. float(other)).","If other is actually a timedelta and you wanted a ratio, swap to division (timedelta / timedelta).","If other is a datetime, rethink the operation: you likely want addition, not multiplication."],"exampleFix":"// before\nimport pandas as pd\ntd = pd.to_timedelta(['1d','2d'])\nout = td * pd.Timestamp('2020-01-01')\n\n// after\nout = td * 2  # scale by integer days","handlingStrategy":"type-guard","validationCode":"import numbers\nif not isinstance(other, (numbers.Integral, numbers.Real, pd.Timedelta)):\n    raise TypeError(f'unsupported multiplier type: {type(other).__name__}')","typeGuard":"def is_supported_td_multiplier(x) -> bool:\n    import numbers\n    return isinstance(x, (numbers.Integral, numbers.Real))","tryCatchPattern":"try:\n    out = td * other\nexcept TypeError as e:\n    if 'Cannot multiply with' in str(e):\n        raise TypeError(f'cast {type(other).__name__} to int/float first') from e\n    raise","preventionTips":["Type-check user-supplied multipliers before arithmetic.","Keep timedelta arithmetic limited to numeric scalars.","Wrap external inputs with float() or int() defensively."],"tags":["timedelta","typeerror","arithmetic","numpy-2"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}