@@ -398,7 +398,11 @@ def trans(x):
398
398
and not is_bool_dtype (result .dtype )
399
399
and not is_string_dtype (result .dtype )
400
400
):
401
- new_result = result .astype (dtype )
401
+ with warnings .catch_warnings ():
402
+ warnings .filterwarnings (
403
+ "ignore" , "overflow encountered in cast" , RuntimeWarning
404
+ )
405
+ new_result = result .astype (dtype )
402
406
403
407
# Adjust tolerances based on floating point size
404
408
size_tols = {4 : 5e-4 , 8 : 5e-8 , 16 : 5e-16 }
@@ -1602,7 +1606,9 @@ def maybe_cast_to_integer_array(arr: list | np.ndarray, dtype: np.dtype) -> np.n
1602
1606
)
1603
1607
casted = np .array (arr , dtype = dtype , copy = False )
1604
1608
else :
1605
- casted = arr .astype (dtype , copy = False )
1609
+ with warnings .catch_warnings ():
1610
+ warnings .filterwarnings ("ignore" , category = RuntimeWarning )
1611
+ casted = arr .astype (dtype , copy = False )
1606
1612
except OverflowError as err :
1607
1613
raise OverflowError (
1608
1614
"The elements provided in the data cannot all be "
@@ -1614,7 +1620,7 @@ def maybe_cast_to_integer_array(arr: list | np.ndarray, dtype: np.dtype) -> np.n
1614
1620
return casted
1615
1621
1616
1622
with warnings .catch_warnings ():
1617
- warnings .filterwarnings ("ignore" )
1623
+ warnings .filterwarnings ("ignore" , category = RuntimeWarning )
1618
1624
if np .array_equal (arr , casted ):
1619
1625
return casted
1620
1626
@@ -1817,7 +1823,9 @@ def np_can_hold_element(dtype: np.dtype, element: Any) -> Any:
1817
1823
# see test_where_complex GH#6345
1818
1824
return dtype .type (element )
1819
1825
1820
- casted = dtype .type (element )
1826
+ with warnings .catch_warnings ():
1827
+ warnings .filterwarnings ("ignore" )
1828
+ casted = dtype .type (element )
1821
1829
if casted == element :
1822
1830
return casted
1823
1831
# otherwise e.g. overflow see test_32878_complex_itemsize
0 commit comments