@@ -36,6 +36,31 @@ def compute_backend(request):
36
36
yield request .param
37
37
38
38
39
+ @pytest .mark .parametrize ("func" , ["mean" , "sum" ])
40
+ @pytest .mark .parametrize ("min_periods" , [1 , 10 ])
41
+ def test_cumulative (d , func , min_periods ) -> None :
42
+ # One dim
43
+ result = getattr (d .cumulative ("z" , min_periods = min_periods ), func )()
44
+ expected = getattr (d .rolling (z = d ["z" ].size , min_periods = min_periods ), func )()
45
+ assert_identical (result , expected )
46
+
47
+ # Multiple dim
48
+ result = getattr (d .cumulative (["z" , "x" ], min_periods = min_periods ), func )()
49
+ expected = getattr (
50
+ d .rolling (z = d ["z" ].size , x = d ["x" ].size , min_periods = min_periods ),
51
+ func ,
52
+ )()
53
+ assert_identical (result , expected )
54
+
55
+
56
+ def test_cumulative_vs_cum (d ) -> None :
57
+ result = d .cumulative ("z" ).sum ()
58
+ expected = d .cumsum ("z" )
59
+ # cumsum drops the coord of the dimension; cumulative doesn't
60
+ expected = expected .assign_coords (z = result ["z" ])
61
+ assert_identical (result , expected )
62
+
63
+
39
64
class TestDataArrayRolling :
40
65
@pytest .mark .parametrize ("da" , (1 , 2 ), indirect = True )
41
66
@pytest .mark .parametrize ("center" , [True , False ])
@@ -485,29 +510,6 @@ def test_rolling_exp_keep_attrs(self, da, func) -> None:
485
510
):
486
511
da .rolling_exp (time = 10 , keep_attrs = True )
487
512
488
- @pytest .mark .parametrize ("func" , ["mean" , "sum" ])
489
- @pytest .mark .parametrize ("min_periods" , [1 , 20 ])
490
- def test_cumulative (self , da , func , min_periods ) -> None :
491
- # One dim
492
- result = getattr (da .cumulative ("time" , min_periods = min_periods ), func )()
493
- expected = getattr (
494
- da .rolling (time = da .time .size , min_periods = min_periods ), func
495
- )()
496
- assert_identical (result , expected )
497
-
498
- # Multiple dim
499
- result = getattr (da .cumulative (["time" , "a" ], min_periods = min_periods ), func )()
500
- expected = getattr (
501
- da .rolling (time = da .time .size , a = da .a .size , min_periods = min_periods ),
502
- func ,
503
- )()
504
- assert_identical (result , expected )
505
-
506
- def test_cumulative_vs_cum (self , da ) -> None :
507
- result = da .cumulative ("time" ).sum ()
508
- expected = da .cumsum ("time" )
509
- assert_identical (result , expected )
510
-
511
513
512
514
class TestDatasetRolling :
513
515
@pytest .mark .parametrize (
@@ -832,25 +834,6 @@ def test_raise_no_warning_dask_rolling_assert_close(self, ds, name) -> None:
832
834
expected = getattr (getattr (ds .rolling (time = 4 ), name )().rolling (x = 3 ), name )()
833
835
assert_allclose (actual , expected )
834
836
835
- @pytest .mark .parametrize ("func" , ["mean" , "sum" ])
836
- @pytest .mark .parametrize ("ds" , (2 ,), indirect = True )
837
- @pytest .mark .parametrize ("min_periods" , [1 , 10 ])
838
- def test_cumulative (self , ds , func , min_periods ) -> None :
839
- # One dim
840
- result = getattr (ds .cumulative ("time" , min_periods = min_periods ), func )()
841
- expected = getattr (
842
- ds .rolling (time = ds .time .size , min_periods = min_periods ), func
843
- )()
844
- assert_identical (result , expected )
845
-
846
- # Multiple dim
847
- result = getattr (ds .cumulative (["time" , "x" ], min_periods = min_periods ), func )()
848
- expected = getattr (
849
- ds .rolling (time = ds .time .size , x = ds .x .size , min_periods = min_periods ),
850
- func ,
851
- )()
852
- assert_identical (result , expected )
853
-
854
837
855
838
@requires_numbagg
856
839
class TestDatasetRollingExp :
0 commit comments