@@ -530,11 +530,16 @@ def _calculate(self, X, y, logger, feat_type):
530
530
kurts = []
531
531
for i in range (X .shape [1 ]):
532
532
if numerical [X .columns [i ] if hasattr (X , "columns" ) else i ]:
533
- kurts .append (
534
- scipy .stats .kurtosis (
535
- X .iloc [:, i ] if hasattr (X , "iloc" ) else X [:, i ]
533
+ if np .isclose (
534
+ np .var (X .iloc [:, i ] if hasattr (X , "iloc" ) else X [:, i ]), 0
535
+ ):
536
+ kurts .append (0 )
537
+ else :
538
+ kurts .append (
539
+ scipy .stats .kurtosis (
540
+ X .iloc [:, i ] if hasattr (X , "iloc" ) else X [:, i ]
541
+ )
536
542
)
537
- )
538
543
return kurts
539
544
540
545
def _calculate_sparse (self , X , y , logger , feat_type ):
@@ -548,7 +553,10 @@ def _calculate_sparse(self, X, y, logger, feat_type):
548
553
if numerical [X .columns [i ] if hasattr (X , "columns" ) else i ]:
549
554
start = X_new .indptr [i ]
550
555
stop = X_new .indptr [i + 1 ]
551
- kurts .append (scipy .stats .kurtosis (X_new .data [start :stop ]))
556
+ if np .isclose (np .var (X_new .data [start :stop ]), 0 ):
557
+ kurts .append (0 )
558
+ else :
559
+ kurts .append (scipy .stats .kurtosis (X_new .data [start :stop ]))
552
560
return kurts
553
561
554
562
@@ -594,9 +602,16 @@ def _calculate(self, X, y, logger, feat_type):
594
602
skews = []
595
603
for i in range (X .shape [1 ]):
596
604
if numerical [X .columns [i ] if hasattr (X , "columns" ) else i ]:
597
- skews .append (
598
- scipy .stats .skew (X .iloc [:, i ] if hasattr (X , "iloc" ) else X [:, i ])
599
- )
605
+ if np .isclose (
606
+ np .var (X .iloc [:, i ] if hasattr (X , "iloc" ) else X [:, i ]), 0
607
+ ):
608
+ skews .append (0 )
609
+ else :
610
+ skews .append (
611
+ scipy .stats .skew (
612
+ X .iloc [:, i ] if hasattr (X , "iloc" ) else X [:, i ]
613
+ )
614
+ )
600
615
return skews
601
616
602
617
def _calculate_sparse (self , X , y , logger , feat_type ):
@@ -610,7 +625,10 @@ def _calculate_sparse(self, X, y, logger, feat_type):
610
625
if numerical [X .columns [i ] if hasattr (X , "columns" ) else i ]:
611
626
start = X_new .indptr [i ]
612
627
stop = X_new .indptr [i + 1 ]
613
- skews .append (scipy .stats .skew (X_new .data [start :stop ]))
628
+ if np .isclose (np .var (X_new .data [start :stop ]), 0 ):
629
+ skews .append (0 )
630
+ else :
631
+ skews .append (scipy .stats .skew (X_new .data [start :stop ]))
614
632
return skews
615
633
616
634
0 commit comments