@@ -600,3 +600,60 @@ def test_different_input_array_raise_exception(name):
600
600
# exception raised is Exception
601
601
with pytest .raises (ValueError , match = msg ):
602
602
getattr (A .ewm (com = 20 , min_periods = 5 ), name )(np .random .randn (50 ))
603
+
604
+
605
+ @pytest .mark .parametrize ("name" , ["var" , "std" , "mean" ])
606
+ def test_ewma_series (series , name ):
607
+ series_result = getattr (series .ewm (com = 10 ), name )()
608
+ assert isinstance (series_result , Series )
609
+
610
+
611
+ @pytest .mark .parametrize ("name" , ["var" , "std" , "mean" ])
612
+ def test_ewma_frame (frame , name ):
613
+ frame_result = getattr (frame .ewm (com = 10 ), name )()
614
+ assert isinstance (frame_result , DataFrame )
615
+
616
+
617
+ def test_ewma_span_com_args (series ):
618
+ A = series .ewm (com = 9.5 ).mean ()
619
+ B = series .ewm (span = 20 ).mean ()
620
+ tm .assert_almost_equal (A , B )
621
+ msg = "comass, span, halflife, and alpha are mutually exclusive"
622
+ with pytest .raises (ValueError , match = msg ):
623
+ series .ewm (com = 9.5 , span = 20 )
624
+
625
+ msg = "Must pass one of comass, span, halflife, or alpha"
626
+ with pytest .raises (ValueError , match = msg ):
627
+ series .ewm ().mean ()
628
+
629
+
630
+ def test_ewma_halflife_arg (series ):
631
+ A = series .ewm (com = 13.932726172912965 ).mean ()
632
+ B = series .ewm (halflife = 10.0 ).mean ()
633
+ tm .assert_almost_equal (A , B )
634
+ msg = "comass, span, halflife, and alpha are mutually exclusive"
635
+ with pytest .raises (ValueError , match = msg ):
636
+ series .ewm (span = 20 , halflife = 50 )
637
+ with pytest .raises (ValueError , match = msg ):
638
+ series .ewm (com = 9.5 , halflife = 50 )
639
+ with pytest .raises (ValueError , match = msg ):
640
+ series .ewm (com = 9.5 , span = 20 , halflife = 50 )
641
+ msg = "Must pass one of comass, span, halflife, or alpha"
642
+ with pytest .raises (ValueError , match = msg ):
643
+ series .ewm ()
644
+
645
+
646
+ def test_ewm_alpha_arg (series ):
647
+ # GH 10789
648
+ s = series
649
+ msg = "Must pass one of comass, span, halflife, or alpha"
650
+ with pytest .raises (ValueError , match = msg ):
651
+ s .ewm ()
652
+
653
+ msg = "comass, span, halflife, and alpha are mutually exclusive"
654
+ with pytest .raises (ValueError , match = msg ):
655
+ s .ewm (com = 10.0 , alpha = 0.5 )
656
+ with pytest .raises (ValueError , match = msg ):
657
+ s .ewm (span = 10.0 , alpha = 0.5 )
658
+ with pytest .raises (ValueError , match = msg ):
659
+ s .ewm (halflife = 10.0 , alpha = 0.5 )
0 commit comments