@@ -688,46 +688,52 @@ def test_numpy_sum(self):
688688 SparseArray (data ), out = out )
689689
690690 def test_cumsum (self ):
691- data = np .arange (10 ).astype (float )
692- out = SparseArray (data ).cumsum ()
693- expected = SparseArray (data .cumsum ())
694- tm .assert_sp_array_equal (out , expected )
691+ non_null_data = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = float )
692+ non_null_expected = SparseArray (non_null_data .cumsum ())
695693
696- # TODO: gh-12855 - return a SparseArray here
697- data [5 ] = np .nan
698- out = SparseArray (data , fill_value = 2 ).cumsum ()
699- self .assertNotIsInstance (out , SparseArray )
700- tm .assert_numpy_array_equal (out , data .cumsum ())
694+ null_data = np .array ([1 , 2 , np .nan , 4 , 5 ], dtype = float )
695+ null_expected = SparseArray (np .array ([1.0 , 3.0 , np .nan , 7.0 , 12.0 ]))
696+
697+ for data , expected in [
698+ (null_data , null_expected ),
699+ (non_null_data , non_null_expected )
700+ ]:
701+ out = SparseArray (data ).cumsum ()
702+ tm .assert_sp_array_equal (out , expected )
701703
702- out = SparseArray (data , fill_value = np .nan ).cumsum ()
703- expected = SparseArray (np .array ([
704- 0 , 1 , 3 , 6 , 10 , np .nan , 16 , 23 , 31 , 40 ]))
705- tm .assert_sp_array_equal (out , expected )
704+ out = SparseArray (data , fill_value = np .nan ).cumsum ()
705+ tm .assert_sp_array_equal (out , expected )
706+
707+ out = SparseArray (data , fill_value = 2 ).cumsum ()
708+ tm .assert_sp_array_equal (out , expected )
706709
707710 def test_numpy_cumsum (self ):
708- data = np .arange (10 ).astype (float )
709- out = np .cumsum (SparseArray (data ))
710- expected = SparseArray (data .cumsum ())
711- tm .assert_sp_array_equal (out , expected )
711+ non_null_data = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = float )
712+ non_null_expected = SparseArray (non_null_data .cumsum ())
712713
713- # TODO: gh-12855 - return a SparseArray here
714- data [5 ] = np .nan
715- out = np .cumsum (SparseArray (data , fill_value = 2 ))
716- self .assertNotIsInstance (out , SparseArray )
717- tm .assert_numpy_array_equal (out , data .cumsum ())
714+ null_data = np .array ([1 , 2 , np .nan , 4 , 5 ], dtype = float )
715+ null_expected = SparseArray (np .array ([1.0 , 3.0 , np .nan , 7.0 , 12.0 ]))
718716
719- out = np .cumsum (SparseArray (data , fill_value = np .nan ))
720- expected = SparseArray (np .array ([
721- 0 , 1 , 3 , 6 , 10 , np .nan , 16 , 23 , 31 , 40 ]))
722- tm .assert_sp_array_equal (out , expected )
717+ for data , expected in [
718+ (null_data , null_expected ),
719+ (non_null_data , non_null_expected )
720+ ]:
721+ out = np .cumsum (SparseArray (data ))
722+ tm .assert_sp_array_equal (out , expected )
723723
724- msg = "the 'dtype' parameter is not supported"
725- tm .assertRaisesRegexp (ValueError , msg , np .cumsum ,
726- SparseArray (data ), dtype = np .int64 )
724+ out = np .cumsum (SparseArray (data , fill_value = np .nan ))
725+ tm .assert_sp_array_equal (out , expected )
727726
728- msg = "the 'out' parameter is not supported"
729- tm .assertRaisesRegexp (ValueError , msg , np .cumsum ,
730- SparseArray (data ), out = out )
727+ out = np .cumsum (SparseArray (data , fill_value = 2 ))
728+ tm .assert_sp_array_equal (out , expected )
729+
730+ msg = "the 'dtype' parameter is not supported"
731+ tm .assertRaisesRegexp (ValueError , msg , np .cumsum ,
732+ SparseArray (data ), dtype = np .int64 )
733+
734+ msg = "the 'out' parameter is not supported"
735+ tm .assertRaisesRegexp (ValueError , msg , np .cumsum ,
736+ SparseArray (data ), out = out )
731737
732738 def test_mean (self ):
733739 data = np .arange (10 ).astype (float )
0 commit comments