Question: I have a list that contains very large integers and I want to cast it into a pandas column with a specific dtype. As an example, if the list contains 2**31, which is outside the limit of int32 dtype, casting it into dtype int32 throws an Overflow Error, which lets me know to use another dtype or handle the number in some other way beforehand. import pandas as pd pd.Series([2**31], dtype='int32') # OverflowError: Python int too large to convert to C long  But if a number is large but inside the dtype limits (i.e. 2**31-1), and some number is added to it which results in a value that is outside the dtype limits, then instead of an OverflowError, the operation is executed without any errors, yet the value is now inverted, becoming a completely wrong number for the column. pd.Series([2**31-1], dtype='int32') + 1 0 -2147483648 dtype: int32  Why is it happening? Why doesn’t it raise an error like the first case? PS. I'm using pandas 2.1.1 and numpy 1.26.0 on Python 3.12.0.

Answer:  Why does an operation on a large integer silently overflow?  As a short answer, that's because of how numpy deals with overflows.  On my platform (with the same versions of Python/Packages as yours) : from platform import * import numpy as np; import pandas as pd system(), version(), machine() python_version(), pd.__version__, np.__version__ ('Linux', '#34~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 7 13:12:03 UTC 2', 'x86_64') ('3.12.0', '2.1.1', '1.26.0')  I can reproduce your issue but with a larger integer than the one you choose as an example : pd.Series([2**63], dtype="int32") raises this :  OverflowError: Python int too large to convert to C long  While pd.Series([2**31], dtype="int32") raises this :  ValueError: Values are too large to be losslessly converted to int32. To cast anyway, use pd.Series(values).astype(int32)  Details Let's agree that you're using two different type of objects, which potentially means two different scenarios, i.e, 1) error raised or 2) no error raised :  pd.Series : the Series constructor pd.Series.add : a method of the former  The construction : pd.Series([2**31], dtype="int32") It is handled behind the scenes by sanitize_array which receives your input (the list [2**31], i.e [2147483648]) and call in this case maybe_cast_to_integer_array. The latter will make a classical NumPy construction using np.array : casted = np.array([2147483648], dtype="int32")   DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays. The conversion of 2147483648 to int32 will fail in the future. For the old behavior, usually: np.array(value).astype(dtype) will give the desired result (the cast overflows). np.array([2147483648], dtype='int32')  You may ask yourself why the warning above doesn't show off while constructing your Series, well that's because pandas silents it. Now, right after casting, pandas calls np.asarray without specifying a dtype to let NumPy infer a dtype (which is int64 here) : arr = np.asarray(arr). And since, casted.dtype < arr.dtype, the ValueError is triggered. The addition : pd.Series([2**31-1], dtype="int32") + 1 This one is delegated to _na_arithmetic_op that receives array([2147483647], dtype=int32) and 1 and try to add them together with the help of _evaluate_standard to make a classical operator.add operation that is equivalent to np.array([2147483647]) + 1 and since the fixed size of NumPy numeric types may cause overflow errors when a value requires more memory than available in the data type, the result is the array([-2147483648], dtype=int32) which is passed to sanitize_array to construct back a Series : pd.Series([2**31-1], dtype="int32") + 1 0 -2147483648 dtype: int32  NB : When you go beyond the limit of the int32, NumPy wraps around to the minimum value : a = np.array([2**31-1], dtype="int32"); b = 1 a+b # this gives array([-2147483648], dtype=int32)  Here is some other examples : def wrap_int32(i, N, l=2**31): return ((i+N) % l) - l wrap_int32(2**31, 0) # -2147483648 wrap_int32(2**31, 1) # -2147483647 wrap_int32(2**31, 2) # -2147483646 wrap_int32(2**31, 3) # -2147483645 # ...    I have a list that contains very large integers and I want to cast it into a pandas column with a specific dtype. As an example, if the list contains 2**31, which is outside the limit of int32 dtype, casting it into dtype int32 throws an OverflowError, which lets me know to use another dtype or handle the number in some other way beforehand.  Maybe you should consider opening an issue so that the arithmetic operations made by pandas raise an error in case of an overflow. And as a workaround (or maybe a solution?) for your usecase, you can try catching upstream the integers that doesn't fall within the int32 range : iint32 = np.iinfo(np.int32) lst = [100, 1234567890000, -1e19, 2**31, 2**31-1, -350] out = [i for i in lst if iint32.min <= i and i <= iint32.max] # [100, 2147483647, -350]