From ab01813c1c493be817b703278e81abece6a03a1d Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Thu, 29 Apr 2021 21:58:22 -0500 Subject: [PATCH 1/2] COMPAT: float() exception type for py310 --- pandas/core/nanops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 92618605e47cc..dc188c3d833d7 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -1589,7 +1589,7 @@ def _ensure_numeric(x): except (TypeError, ValueError): try: x = x.astype(np.float64) - except ValueError as err: + except (TypeError, ValueError) as err: # GH#29941 we get here with object arrays containing strs raise TypeError(f"Could not convert {x} to numeric") from err else: From 0113c67f9de19f12263b1e807cc56b4ee5da2606 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Thu, 29 Apr 2021 22:59:54 -0500 Subject: [PATCH 2/2] COMPAT: float() exception type for py310 --- pandas/core/nanops.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index dc188c3d833d7..19fd48a772493 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -1589,7 +1589,7 @@ def _ensure_numeric(x): except (TypeError, ValueError): try: x = x.astype(np.float64) - except (TypeError, ValueError) as err: + except ValueError as err: # GH#29941 we get here with object arrays containing strs raise TypeError(f"Could not convert {x} to numeric") from err else: @@ -1598,7 +1598,7 @@ def _ensure_numeric(x): elif not (is_float(x) or is_integer(x) or is_complex(x)): try: x = float(x) - except ValueError: + except (TypeError, ValueError): # e.g. "1+1j" or "foo" try: x = complex(x)