Skip to content

Commit 22d6852

Browse files
jbrockmendelNico Cernek
authored and
Nico Cernek
committed
BUG: fix TypeError raised in maybe_downcast_numeric (pandas-dev#29103)
1 parent c511acd commit 22d6852

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

pandas/core/dtypes/cast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def trans(x):
202202
r = result.ravel()
203203
arr = np.array([r[0]])
204204

205-
if isna(arr).any() or not np.allclose(arr, trans(arr).astype(dtype), rtol=0):
205+
if isna(arr).any():
206206
# if we have any nulls, then we are done
207207
return result
208208

pandas/core/groupby/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def aggregate(self, func=None, *args, **kwargs):
262262

263263
try:
264264
return self._python_agg_general(func, *args, **kwargs)
265-
except AssertionError:
265+
except (AssertionError, TypeError):
266266
raise
267267
except Exception:
268268
result = self._aggregate_named(func, *args, **kwargs)

pandas/tests/dtypes/cast/test_downcast.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import decimal
2+
13
import numpy as np
24
import pytest
35

@@ -25,6 +27,13 @@
2527
"infer",
2628
np.array([8, 8, 8, 8, 9], dtype=np.int64),
2729
),
30+
(
31+
# This is a judgement call, but we do _not_ downcast Decimal
32+
# objects
33+
np.array([decimal.Decimal(0.0)]),
34+
"int64",
35+
np.array([decimal.Decimal(0.0)]),
36+
),
2837
],
2938
)
3039
def test_downcast(arr, expected, dtype):

0 commit comments

Comments
 (0)