Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF: dont _try_cast for user-defined functions #29698

Merged
merged 26 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
daaddad
REF: make _aggregate_series_pure_python extraction behave like the cy…
jbrockmendel Nov 15, 2019
18bb6c9
blackify
jbrockmendel Nov 15, 2019
201bc27
add tests
jbrockmendel Nov 15, 2019
f4799aa
Merge branch 'master' of https://github.com/pandas-dev/pandas into fa…
jbrockmendel Nov 16, 2019
61f32e5
added test
jbrockmendel Nov 16, 2019
2f96ac7
Merge branch 'master' of https://github.com/pandas-dev/pandas into fa…
jbrockmendel Nov 16, 2019
fb9f171
avoid _values getattr pattern
jbrockmendel Nov 16, 2019
30c1245
Merge branch 'master' of https://github.com/pandas-dev/pandas into fa…
jbrockmendel Nov 17, 2019
d542515
todo comment
jbrockmendel Nov 17, 2019
71b21c7
simplify _transform_fast
jbrockmendel Nov 17, 2019
640710a
remove _try_casts
jbrockmendel Nov 17, 2019
a0676fb
comments
jbrockmendel Nov 17, 2019
9383bec
Merge branch 'master' of https://github.com/pandas-dev/pandas into fa…
jbrockmendel Nov 17, 2019
7ed5aa5
Merge branch 'master' of https://github.com/pandas-dev/pandas into fa…
jbrockmendel Nov 18, 2019
ab125ec
Whatsnew
jbrockmendel Nov 18, 2019
f133746
Merge branch 'master' of https://github.com/pandas-dev/pandas into fa…
jbrockmendel Nov 18, 2019
869ef56
Merge branch 'master' of https://github.com/pandas-dev/pandas into fa…
jbrockmendel Nov 18, 2019
5ac4679
Merge branch 'master' of https://github.com/pandas-dev/pandas into fa…
jbrockmendel Nov 18, 2019
96df6d9
remove comments
jbrockmendel Nov 18, 2019
50f579b
Merge branch 'master' of https://github.com/pandas-dev/pandas into fa…
jbrockmendel Nov 18, 2019
dceda2f
revert parts in other PRs
jbrockmendel Nov 18, 2019
1965e22
comment
jbrockmendel Nov 18, 2019
271cf31
Merge branch 'master' of https://github.com/pandas-dev/pandas into fa…
jbrockmendel Nov 19, 2019
4a0acad
Merge branch 'master' of https://github.com/pandas-dev/pandas into fa…
jbrockmendel Nov 20, 2019
0e16f9d
Merge branch 'master' of https://github.com/pandas-dev/pandas into fa…
jbrockmendel Nov 21, 2019
0cccfa5
remove note
jbrockmendel Nov 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ Groupby/resample/rolling
- Bug in :meth:`DataFrameGroupby.agg` not able to use lambda function with named aggregation (:issue:`27519`)
- Bug in :meth:`DataFrame.groupby` losing column name information when grouping by a categorical column (:issue:`28787`)
- Bug in :meth:`DataFrameGroupBy.rolling().quantile()` ignoring ``interpolation`` keyword argument (:issue:`28779`)
- Bug in :meth:`DataFrameGroupBy.agg` with timezone-aware datetime64 column incorrect casting results to the original dtype (:issue:`29641`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a sub-section in api-changes. this is a non-trivial change i think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, but since this note is orthogonal to this PR, im going to do that in a separate PR. removing this note for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k


Reshaping
^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ def apply_raw(self):
if "Function does not reduce" not in str(err):
# catch only ValueError raised intentionally in libreduction
raise
# We expect np.apply_along_axis to give a two-dimensional result, or
# also raise.
result = np.apply_along_axis(self.f, self.axis, self.values)

# TODO: mixed type case
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,12 +1050,12 @@ def _aggregate_frame(self, func, *args, **kwargs) -> DataFrame:
if axis != obj._info_axis_number:
for name, data in self:
fres = func(data, *args, **kwargs)
result[name] = self._try_cast(fres, data)
result[name] = fres
else:
for name in self.indices:
data = self.get_group(name, obj=obj)
fres = func(data, *args, **kwargs)
result[name] = self._try_cast(fres, data)
result[name] = fres

return self._wrap_frame_output(result, obj)

Expand Down Expand Up @@ -1374,6 +1374,8 @@ def _transform_fast(self, result: DataFrame, obj: DataFrame, func_nm) -> DataFra
output = []
for i, _ in enumerate(result.columns):
res = algorithms.take_1d(result.iloc[:, i].values, ids)
# TODO: we have no test cases that get here with EA dtypes;
# try_cast may not be needed if EAs never get here
if cast:
res = self._try_cast(res, obj.iloc[:, i])
output.append(res)
Expand Down