Skip to content

Conversation

@sanchit122006
Copy link

@sanchit122006 sanchit122006 commented Dec 21, 2025

Fixed Rounding of an empty Series

PR summary

This pull request fixes a bug where calling round() on an empty Series raises a TypeError instead of returning an empty Series. The change makes Series.round() behave consistently with other numeric operations that already handle empty Series/DataFrames gracefully.

What does this change?

  • Updates Series.round() so that it does not raise on an empty Series with object dtype.
  • Ensures pd.Series().round(4) returns an empty Series instead of failing.
  • Adds a regression test to cover this edge case and prevent future breakage.

Why is this change needed?

In the current behavior, code that works for non‑empty Series can unexpectedly fail when it encounters an empty Series and calls round(). This is surprising because other operations like min, cumsum, and shift already handle the empty case without errors. Aligning round() with these operations removes this inconsistency and avoids hard‑to‑debug edge cases in real pipelines.

How was this tested?

  • Added a new test that checks pd.Series().round(4) and verifies it does not raise and returns an empty Series.
  • Ran the relevant Series tests locally to confirm the change passes and does not affect non‑empty numeric Series.
  • Verified that the behavior for normal numeric Series is unchanged.

Added section

It verifies that calling round(4) on empty Series of object, float, and int dtypes returns an identical empty Series without raising any error
image

REPL Tests

1. Verification of the

Fix (object dtype)

Rounding an empty object dtype Series no longer crashes; it returns an empty Series

image

2. Verification of Consistency (float64 dtype)

Rounding an empty float64 Series still works and matches the behavior of the fixed object version

image

3. No Regressions:

Rounding a normal Series with data (like 1.123 to 1.12) still works perfectly.

image

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, but I am negative on the proposed change. See the linked issue for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Rounding of an empty Series should return empty Series

2 participants