API: should apply also follow result_type for axis=0 ? #19570
Labels
API Design
Apply
Apply, Aggregate, Transform, Map
Enhancement
Needs Discussion
Requires discussion from core team before further action
Follow-up issue on #18577
In that PR @jreback cleaned up the
apply(..., axis=1)
result shape inconsistencies, and we added a keyword to control this.For example, when the applied function returns an array or a list, it now defaults to returning a Series of those objects, or expanding it to multiple columns if you pass
result_type
explicitly:However, for
axis=0
, the default, we don't yet follow the same rules / the keyword in all cases. Some examples:For list, it depends on the length (and if the length matches, it preserves the original index instead of new range index):
(
result_type='expand'
andresult_type='broadcast'
do work correctly here)For an array, it expands when the length does not match (so different as for
axis=1
, and also different as for list):So the question is: should we follow the same rules for
axis=0
as foraxis=1
?I would say: ideally yes. But doing so might break some behaviour (although it might be possible to do that with warnings).
The text was updated successfully, but these errors were encountered: