Skip to content

Commit 36e60d9

Browse files
Backport PR #42046: BUG: Don't supply name to Series when using 'size' with agg/apply (#42051)
Co-authored-by: Richard Shadrach <[email protected]>
1 parent f8cf197 commit 36e60d9

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pandas/core/apply.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ def apply_str(self) -> FrameOrSeriesUnion:
842842
# Special-cased because DataFrame.size returns a single scalar
843843
obj = self.obj
844844
value = obj.shape[self.axis]
845-
return obj._constructor_sliced(value, index=self.agg_axis, name="size")
845+
return obj._constructor_sliced(value, index=self.agg_axis)
846846
return super().apply_str()
847847

848848

pandas/tests/apply/test_frame_apply.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1279,9 +1279,9 @@ def test_size_as_str(how, axis):
12791279
# on the columns
12801280
result = getattr(df, how)("size", axis=axis)
12811281
if axis == 0 or axis == "index":
1282-
expected = Series(df.shape[0], index=df.columns, name="size")
1282+
expected = Series(df.shape[0], index=df.columns)
12831283
else:
1284-
expected = Series(df.shape[1], index=df.index, name="size")
1284+
expected = Series(df.shape[1], index=df.index)
12851285
tm.assert_series_equal(result, expected)
12861286

12871287

0 commit comments

Comments
 (0)