|
6 | 6 | tests.frame.test_cumulative
|
7 | 7 | """
|
8 | 8 |
|
| 9 | +import re |
| 10 | + |
9 | 11 | import numpy as np
|
10 | 12 | import pytest
|
11 | 13 |
|
@@ -155,3 +157,55 @@ def test_cumprod_timedelta(self):
|
155 | 157 | ser = pd.Series([pd.Timedelta(days=1), pd.Timedelta(days=3)])
|
156 | 158 | with pytest.raises(TypeError, match="cumprod not supported for Timedelta"):
|
157 | 159 | ser.cumprod()
|
| 160 | + |
| 161 | + @pytest.mark.parametrize( |
| 162 | + "data, op, skipna, expected_data", |
| 163 | + [ |
| 164 | + ([], "cumsum", True, []), |
| 165 | + ([], "cumsum", False, []), |
| 166 | + (["x", "z", "y"], "cumsum", True, ["x", "xz", "xzy"]), |
| 167 | + (["x", "z", "y"], "cumsum", False, ["x", "xz", "xzy"]), |
| 168 | + (["x", pd.NA, "y"], "cumsum", True, ["x", pd.NA, "xy"]), |
| 169 | + (["x", pd.NA, "y"], "cumsum", False, ["x", pd.NA, pd.NA]), |
| 170 | + ([pd.NA, "x", "y"], "cumsum", True, [pd.NA, "x", "xy"]), |
| 171 | + ([pd.NA, "x", "y"], "cumsum", False, [pd.NA, pd.NA, pd.NA]), |
| 172 | + ([pd.NA, pd.NA, pd.NA], "cumsum", True, [pd.NA, pd.NA, pd.NA]), |
| 173 | + ([pd.NA, pd.NA, pd.NA], "cumsum", False, [pd.NA, pd.NA, pd.NA]), |
| 174 | + ([], "cummin", True, []), |
| 175 | + ([], "cummin", False, []), |
| 176 | + (["y", "z", "x"], "cummin", True, ["y", "y", "x"]), |
| 177 | + (["y", "z", "x"], "cummin", False, ["y", "y", "x"]), |
| 178 | + (["y", pd.NA, "x"], "cummin", True, ["y", pd.NA, "x"]), |
| 179 | + (["y", pd.NA, "x"], "cummin", False, ["y", pd.NA, pd.NA]), |
| 180 | + ([pd.NA, "y", "x"], "cummin", True, [pd.NA, "y", "x"]), |
| 181 | + ([pd.NA, "y", "x"], "cummin", False, [pd.NA, pd.NA, pd.NA]), |
| 182 | + ([pd.NA, pd.NA, pd.NA], "cummin", True, [pd.NA, pd.NA, pd.NA]), |
| 183 | + ([pd.NA, pd.NA, pd.NA], "cummin", False, [pd.NA, pd.NA, pd.NA]), |
| 184 | + ([], "cummax", True, []), |
| 185 | + ([], "cummax", False, []), |
| 186 | + (["x", "z", "y"], "cummax", True, ["x", "z", "z"]), |
| 187 | + (["x", "z", "y"], "cummax", False, ["x", "z", "z"]), |
| 188 | + (["x", pd.NA, "y"], "cummax", True, ["x", pd.NA, "y"]), |
| 189 | + (["x", pd.NA, "y"], "cummax", False, ["x", pd.NA, pd.NA]), |
| 190 | + ([pd.NA, "x", "y"], "cummax", True, [pd.NA, "x", "y"]), |
| 191 | + ([pd.NA, "x", "y"], "cummax", False, [pd.NA, pd.NA, pd.NA]), |
| 192 | + ([pd.NA, pd.NA, pd.NA], "cummax", True, [pd.NA, pd.NA, pd.NA]), |
| 193 | + ([pd.NA, pd.NA, pd.NA], "cummax", False, [pd.NA, pd.NA, pd.NA]), |
| 194 | + ], |
| 195 | + ) |
| 196 | + def test_cum_methods_pyarrow_strings( |
| 197 | + self, pyarrow_string_dtype, data, op, skipna, expected_data |
| 198 | + ): |
| 199 | + # https://github.com/pandas-dev/pandas/pull/60633 |
| 200 | + ser = pd.Series(data, dtype=pyarrow_string_dtype) |
| 201 | + method = getattr(ser, op) |
| 202 | + expected = pd.Series(expected_data, dtype=pyarrow_string_dtype) |
| 203 | + result = method(skipna=skipna) |
| 204 | + tm.assert_series_equal(result, expected) |
| 205 | + |
| 206 | + def test_cumprod_pyarrow_strings(self, pyarrow_string_dtype, skipna): |
| 207 | + # https://github.com/pandas-dev/pandas/pull/60633 |
| 208 | + ser = pd.Series(list("xyz"), dtype=pyarrow_string_dtype) |
| 209 | + msg = re.escape(f"operation 'cumprod' not supported for dtype '{ser.dtype}'") |
| 210 | + with pytest.raises(TypeError, match=msg): |
| 211 | + ser.cumprod(skipna=skipna) |
0 commit comments