Skip to content

Backport PR #30905 on branch 1.0.x (BUG: SystemError in df.sum) #31044

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions pandas/_libs/tslibs/c_timestamp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ def integer_op_not_supported(obj):
# the caller; mypy finds this more palatable.
cls = type(obj).__name__

# GH#30886 using an fstring raises SystemError
int_addsub_msg = (
f"Addition/subtraction of integers and integer-arrays with {cls} is "
"Addition/subtraction of integers and integer-arrays with {cls} is "
"no longer supported. Instead of adding/subtracting `n`, "
"use `n * obj.freq`"
)
).format(cls=cls)
return TypeError(int_addsub_msg)


Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,16 @@ def test_sum_bool(self, float_frame):
bools.sum(1)
bools.sum(0)

def test_sum_mixed_datetime(self):
# GH#30886
df = pd.DataFrame(
{"A": pd.date_range("2000", periods=4), "B": [1, 2, 3, 4]}
).reindex([2, 3, 4])
result = df.sum()

expected = pd.Series({"B": 7.0})
tm.assert_series_equal(result, expected)

def test_mean_corner(self, float_frame, float_string_frame):
# unit test when have object data
the_mean = float_string_frame.mean(axis=0)
Expand Down