@@ -50,19 +50,30 @@ def numeric_stats_numpy(
5050 index_values = vc .index .values
5151
5252 # FIXME: can be performance optimized by using weights in std, var, kurt and skew...
53-
54- return {
55- "mean" : np .average (index_values , weights = vc .values ),
56- "std" : np .std (present_values , ddof = 1 ),
57- "variance" : np .var (present_values , ddof = 1 ),
58- "min" : np .min (index_values ),
59- "max" : np .max (index_values ),
60- # Unbiased kurtosis obtained using Fisher's definition (kurtosis of normal == 0.0). Normalized by N-1.
61- "kurtosis" : series .kurt (),
62- # Unbiased skew normalized by N-1
63- "skewness" : series .skew (),
64- "sum" : np .dot (index_values , vc .values ),
65- }
53+ if len (index_values ):
54+ return {
55+ "mean" : np .average (index_values , weights = vc .values ),
56+ "std" : np .std (present_values , ddof = 1 ),
57+ "variance" : np .var (present_values , ddof = 1 ),
58+ "min" : np .min (index_values ),
59+ "max" : np .max (index_values ),
60+ # Unbiased kurtosis obtained using Fisher's definition (kurtosis of normal == 0.0). Normalized by N-1.
61+ "kurtosis" : series .kurt (),
62+ # Unbiased skew normalized by N-1
63+ "skewness" : series .skew (),
64+ "sum" : np .dot (index_values , vc .values ),
65+ }
66+ else : # Empty numerical series
67+ return {
68+ "mean" : np .nan ,
69+ "std" : 0.0 ,
70+ "variance" : 0.0 ,
71+ "min" : np .nan ,
72+ "max" : np .nan ,
73+ "kurtosis" : 0.0 ,
74+ "skewness" : 0.0 ,
75+ "sum" : 0 ,
76+ }
6677
6778
6879@describe_numeric_1d .register
@@ -151,13 +162,14 @@ def pandas_describe_numeric_1d(
151162 else :
152163 stats ["monotonic" ] = 0
153164
154- stats .update (
155- histogram_compute (
156- config ,
157- value_counts [~ infinity_index ].index .values ,
158- summary ["n_distinct" ],
159- weights = value_counts [~ infinity_index ].values ,
165+ if len (value_counts [~ infinity_index ].index .values ) > 0 :
166+ stats .update (
167+ histogram_compute (
168+ config ,
169+ value_counts [~ infinity_index ].index .values ,
170+ summary ["n_distinct" ],
171+ weights = value_counts [~ infinity_index ].values ,
172+ )
160173 )
161- )
162174
163175 return config , series , stats
0 commit comments