Skip to content

Commit e375550

Browse files
committed
BUG: remove convert_numeric=True from groupbys
perform soft-conversion of numeric dtypes instead
1 parent dc1ca7b commit e375550

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

pandas/core/common.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,17 +1527,22 @@ def _possibly_convert_objects(values, convert_dates=True,
15271527
values, convert_datetime=convert_dates)
15281528

15291529
# convert to numeric
1530-
if convert_numeric and values.dtype == np.object_:
1531-
try:
1532-
new_values = lib.maybe_convert_numeric(
1533-
values, set(), coerce_numeric=True)
1530+
if values.dtype == np.object_:
1531+
if convert_numeric:
1532+
try:
1533+
new_values = lib.maybe_convert_numeric(
1534+
values, set(), coerce_numeric=True)
15341535

1535-
# if we are all nans then leave me alone
1536-
if not isnull(new_values).all():
1537-
values = new_values
1536+
# if we are all nans then leave me alone
1537+
if not isnull(new_values).all():
1538+
values = new_values
15381539

1539-
except:
1540-
pass
1540+
except:
1541+
pass
1542+
else:
1543+
1544+
# soft-conversion
1545+
values = lib.maybe_convert_objects(values)
15411546

15421547
return values
15431548

pandas/core/groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,7 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
22662266
# if we have date/time like in the original, then coerce dates
22672267
# as we are stacking can easily have object dtypes here
22682268
cd = 'coerce' if self.obj.ndim == 2 and self.obj.dtypes.isin(_DATELIKE_DTYPES).any() else True
2269-
return result.convert_objects(convert_dates=cd, convert_numeric=True)
2269+
return result.convert_objects(convert_dates=cd)
22702270

22712271
else:
22722272
# only coerce dates if we find at least 1 datetime

0 commit comments

Comments
 (0)