Skip to content

Commit b09f671

Browse files
Aloqeelymroeschke
authored andcommitted
Fix DataFrame.cumsum failing when dtype is timedelta64[ns] (pandas-dev#58028)
* Fix DataFrame.cumsum failing when dtype is timedelta64[ns] * Pre-commit * Remove comment Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> * Update whatsnew --------- Co-authored-by: Abdulaziz Aloqeely <52792999+DAzVise@users.noreply.github.com> Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
1 parent e3edab1 commit b09f671

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pandas/core/array_algos/datetimelike_accumulations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def _cum_func(
4949
if not skipna:
5050
mask = np.maximum.accumulate(mask)
5151

52-
result = func(y)
52+
# GH 57956
53+
result = func(y, axis=0)
5354
result[mask] = iNaT
5455

5556
if values.dtype.kind in "mM":

pandas/tests/series/test_cumulative.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,25 @@ def test_cummin_cummax_datetimelike(self, ts, method, skipna, exp_tdi):
9191
result = getattr(ser, method)(skipna=skipna)
9292
tm.assert_series_equal(expected, result)
9393

94+
def test_cumsum_datetimelike(self):
95+
# GH#57956
96+
df = pd.DataFrame(
97+
[
98+
[pd.Timedelta(0), pd.Timedelta(days=1)],
99+
[pd.Timedelta(days=2), pd.NaT],
100+
[pd.Timedelta(hours=-6), pd.Timedelta(hours=12)],
101+
]
102+
)
103+
result = df.cumsum()
104+
expected = pd.DataFrame(
105+
[
106+
[pd.Timedelta(0), pd.Timedelta(days=1)],
107+
[pd.Timedelta(days=2), pd.NaT],
108+
[pd.Timedelta(days=1, hours=18), pd.Timedelta(days=1, hours=12)],
109+
]
110+
)
111+
tm.assert_frame_equal(result, expected)
112+
94113
@pytest.mark.parametrize(
95114
"func, exp",
96115
[

0 commit comments

Comments
 (0)