Skip to content

Commit 2f9259c

Browse files
committed
review comments
1 parent df05308 commit 2f9259c

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

doc/source/whatsnew/v0.25.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ of ``object`` dtype. :attr:`Series.str` will now infer the dtype data *within* t
273273
ufuncs on Extension Dtype
274274
^^^^^^^^^^^^^^^^^^^^^^^^^
275275

276-
Operations with ``numpy`` ufuncs on Extension Arrays, including Sparse Dtypes will now preserve the
276+
Operations with ``numpy`` ufuncs on DataFrames with Extension Arrays, including Sparse Dtypes will now preserve the
277277
resulting dtypes to same as the input dtype; previously this would coerce to a dense dtype. (:issue:`23743`)
278278

279279
.. ipython:: python

pandas/core/groupby/groupby.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ def _add_numeric_operations(cls):
12981298
"""
12991299

13001300
def groupby_function(name, alias, npfunc,
1301-
numeric_only=True, _convert=False,
1301+
numeric_only=True,
13021302
min_count=-1):
13031303

13041304
_local_template = """
@@ -1320,27 +1320,30 @@ def f(self, **kwargs):
13201320
kwargs['min_count'] = min_count
13211321

13221322
self._set_group_selection()
1323+
1324+
# try a cython aggregation if we can
13231325
try:
13241326
return self._cython_agg_general(
13251327
alias, alt=npfunc, **kwargs)
13261328
except AssertionError as e:
13271329
raise SpecificationError(str(e))
13281330
except Exception:
1329-
result = self.aggregate(
1330-
lambda x: npfunc(x, axis=self.axis))
1331-
1332-
# coerce the columns if we can
1333-
if isinstance(result, DataFrame):
1334-
for col in result.columns:
1335-
result[col] = self._try_cast(
1336-
result[col], self.obj[col])
1337-
else:
1338-
result = self._try_cast(
1339-
result, self.obj)
1340-
1341-
if _convert:
1342-
result = result._convert(datetime=True)
1343-
return result
1331+
pass
1332+
1333+
# apply a non-cython aggregation
1334+
result = self.aggregate(
1335+
lambda x: npfunc(x, axis=self.axis))
1336+
1337+
# coerce the resulting columns if we can
1338+
if isinstance(result, DataFrame):
1339+
for col in result.columns:
1340+
result[col] = self._try_cast(
1341+
result[col], self.obj[col])
1342+
else:
1343+
result = self._try_cast(
1344+
result, self.obj)
1345+
1346+
return result
13441347

13451348
set_function_name(f, name, cls)
13461349

pandas/core/internals/blocks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,8 +1776,16 @@ def _try_cast_result(self, result, dtype=None):
17761776
"""
17771777
if we have an operation that operates on for example floats
17781778
we want to try to cast back to our EA here if possible
1779+
1780+
result could be a 2-D numpy array, e.g. the result of
1781+
a numeric operation; but it must be shape (1, X) because
1782+
we by-definition operate on the ExtensionBlocks one-by-one
1783+
1784+
result could also be an EA Array itself, in which case it
1785+
is already a 1-D array
17791786
"""
17801787
try:
1788+
17811789
result = self._holder._from_sequence(
17821790
np.asarray(result).ravel(), dtype=dtype)
17831791
except Exception:

pandas/tests/groupby/test_function.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,7 @@ def scipy_sem(*args, **kwargs):
479479
('last', lambda x: x.iloc[-1]),
480480
('count', np.size),
481481
pytest.param(
482-
'sem', scipy_sem, marks=[pytest.mark.skipif(
483-
td._skip_if_no_scipy(), reason='scipy not installed')])])
482+
'sem', scipy_sem, marks=td.skip_if_no_scipy)])
484483
def test_ops_general(op, targop):
485484
df = DataFrame(np.random.randn(1000))
486485
labels = np.random.randint(0, 50, size=1000).astype(float)

0 commit comments

Comments
 (0)