|
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 |
|
@@ -227,3 +229,55 @@ def test_cumprod_timedelta(self):
|
227 | 229 | ser = pd.Series([pd.Timedelta(days=1), pd.Timedelta(days=3)])
|
228 | 230 | with pytest.raises(TypeError, match="cumprod not supported for Timedelta"):
|
229 | 231 | ser.cumprod()
|
| 232 | + |
| 233 | + @pytest.mark.parametrize( |
| 234 | + "data, op, skipna, expected_data", |
| 235 | + [ |
| 236 | + ([], "cumsum", True, []), |
| 237 | + ([], "cumsum", False, []), |
| 238 | + (["x", "z", "y"], "cumsum", True, ["x", "xz", "xzy"]), |
| 239 | + (["x", "z", "y"], "cumsum", False, ["x", "xz", "xzy"]), |
| 240 | + (["x", pd.NA, "y"], "cumsum", True, ["x", pd.NA, "xy"]), |
| 241 | + (["x", pd.NA, "y"], "cumsum", False, ["x", pd.NA, pd.NA]), |
| 242 | + ([pd.NA, "x", "y"], "cumsum", True, [pd.NA, "x", "xy"]), |
| 243 | + ([pd.NA, "x", "y"], "cumsum", False, [pd.NA, pd.NA, pd.NA]), |
| 244 | + ([pd.NA, pd.NA, pd.NA], "cumsum", True, [pd.NA, pd.NA, pd.NA]), |
| 245 | + ([pd.NA, pd.NA, pd.NA], "cumsum", False, [pd.NA, pd.NA, pd.NA]), |
| 246 | + ([], "cummin", True, []), |
| 247 | + ([], "cummin", False, []), |
| 248 | + (["y", "z", "x"], "cummin", True, ["y", "y", "x"]), |
| 249 | + (["y", "z", "x"], "cummin", False, ["y", "y", "x"]), |
| 250 | + (["y", pd.NA, "x"], "cummin", True, ["y", pd.NA, "x"]), |
| 251 | + (["y", pd.NA, "x"], "cummin", False, ["y", pd.NA, pd.NA]), |
| 252 | + ([pd.NA, "y", "x"], "cummin", True, [pd.NA, "y", "x"]), |
| 253 | + ([pd.NA, "y", "x"], "cummin", False, [pd.NA, pd.NA, pd.NA]), |
| 254 | + ([pd.NA, pd.NA, pd.NA], "cummin", True, [pd.NA, pd.NA, pd.NA]), |
| 255 | + ([pd.NA, pd.NA, pd.NA], "cummin", False, [pd.NA, pd.NA, pd.NA]), |
| 256 | + ([], "cummax", True, []), |
| 257 | + ([], "cummax", False, []), |
| 258 | + (["x", "z", "y"], "cummax", True, ["x", "z", "z"]), |
| 259 | + (["x", "z", "y"], "cummax", False, ["x", "z", "z"]), |
| 260 | + (["x", pd.NA, "y"], "cummax", True, ["x", pd.NA, "y"]), |
| 261 | + (["x", pd.NA, "y"], "cummax", False, ["x", pd.NA, pd.NA]), |
| 262 | + ([pd.NA, "x", "y"], "cummax", True, [pd.NA, "x", "y"]), |
| 263 | + ([pd.NA, "x", "y"], "cummax", False, [pd.NA, pd.NA, pd.NA]), |
| 264 | + ([pd.NA, pd.NA, pd.NA], "cummax", True, [pd.NA, pd.NA, pd.NA]), |
| 265 | + ([pd.NA, pd.NA, pd.NA], "cummax", False, [pd.NA, pd.NA, pd.NA]), |
| 266 | + ], |
| 267 | + ) |
| 268 | + def test_cum_methods_pyarrow_strings( |
| 269 | + self, pyarrow_string_dtype, data, op, skipna, expected_data |
| 270 | + ): |
| 271 | + # https://github.com/pandas-dev/pandas/pull/60633 |
| 272 | + ser = pd.Series(data, dtype=pyarrow_string_dtype) |
| 273 | + method = getattr(ser, op) |
| 274 | + expected = pd.Series(expected_data, dtype=pyarrow_string_dtype) |
| 275 | + result = method(skipna=skipna) |
| 276 | + tm.assert_series_equal(result, expected) |
| 277 | + |
| 278 | + def test_cumprod_pyarrow_strings(self, pyarrow_string_dtype, skipna): |
| 279 | + # https://github.com/pandas-dev/pandas/pull/60633 |
| 280 | + ser = pd.Series(list("xyz"), dtype=pyarrow_string_dtype) |
| 281 | + msg = re.escape(f"operation 'cumprod' not supported for dtype '{ser.dtype}'") |
| 282 | + with pytest.raises(TypeError, match=msg): |
| 283 | + ser.cumprod(skipna=skipna) |
0 commit comments