@@ -629,8 +629,37 @@ def _check_ew_ndarray(self, func, preserve_nan=False):
629
629
arr = randn (50 )
630
630
arr [:10 ] = np .NaN
631
631
arr [- 10 :] = np .NaN
632
-
633
- # ??? check something
632
+ s = Series (arr )
633
+
634
+ # check min_periods
635
+ # GH 7898
636
+ result = func (s , 50 , min_periods = 2 )
637
+ self .assertTrue (np .isnan (result .values [:11 ]).all ())
638
+ self .assertFalse (np .isnan (result .values [11 :]).any ())
639
+
640
+ for min_periods in (0 , 1 ):
641
+ result = func (s , 50 , min_periods = min_periods )
642
+ if func == mom .ewma :
643
+ self .assertTrue (np .isnan (result .values [:10 ]).all ())
644
+ self .assertFalse (np .isnan (result .values [10 :]).any ())
645
+ else :
646
+ # ewmstd, ewmvol, ewmvar *should* require at least two values,
647
+ # but currently require only one, for some reason
648
+ self .assertTrue (np .isnan (result .values [:10 ]).all ())
649
+ self .assertFalse (np .isnan (result .values [10 :]).any ())
650
+
651
+ # check series of length 0
652
+ result = func (Series ([]), 50 , min_periods = min_periods )
653
+ assert_series_equal (result , Series ([]))
654
+
655
+ # check series of length 1
656
+ result = func (Series ([1. ]), 50 , min_periods = min_periods )
657
+ if func == mom .ewma :
658
+ assert_series_equal (result , Series ([1. ]))
659
+ else :
660
+ # ewmstd, ewmvol, ewmvar *should* require at least two values,
661
+ # so should return NaN, but currently require one, so return 0.
662
+ assert_series_equal (result , Series ([0. ]))
634
663
635
664
# pass in ints
636
665
result2 = func (np .arange (50 ), span = 10 )
@@ -752,9 +781,32 @@ def _check_binary_ew(self, func):
752
781
B [- 10 :] = np .NaN
753
782
754
783
result = func (A , B , 20 , min_periods = 5 )
755
-
756
- self .assertTrue (np .isnan (result .values [:15 ]).all ())
757
- self .assertFalse (np .isnan (result .values [15 :]).any ())
784
+ self .assertTrue (np .isnan (result .values [:14 ]).all ())
785
+ self .assertFalse (np .isnan (result .values [14 :]).any ())
786
+
787
+ # GH 7898
788
+ for min_periods in (0 , 1 , 2 ):
789
+ result = func (A , B , 20 , min_periods = min_periods )
790
+ # binary functions (ewmcov, ewmcorr) *should* require at least two values
791
+ if (func == mom .ewmcov ) and (min_periods <= 1 ):
792
+ # currenty ewmcov requires only one value, for some reason.
793
+ self .assertTrue (np .isnan (result .values [:10 ]).all ())
794
+ self .assertFalse (np .isnan (result .values [10 :]).any ())
795
+ else :
796
+ self .assertTrue (np .isnan (result .values [:11 ]).all ())
797
+ self .assertFalse (np .isnan (result .values [11 :]).any ())
798
+
799
+ # check series of length 0
800
+ result = func (Series ([]), Series ([]), 50 , min_periods = min_periods )
801
+ assert_series_equal (result , Series ([]))
802
+
803
+ # check series of length 1
804
+ result = func (Series ([1. ]), Series ([1. ]), 50 , min_periods = min_periods )
805
+ if (func == mom .ewmcov ) and (min_periods <= 1 ):
806
+ # currenty ewmcov requires only one value, for some reason.
807
+ assert_series_equal (result , Series ([0. ]))
808
+ else :
809
+ assert_series_equal (result , Series ([np .NaN ]))
758
810
759
811
self .assertRaises (Exception , func , A , randn (50 ), 20 , min_periods = 5 )
760
812
0 commit comments