File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
src/Microsoft.Data.Analysis
test/Microsoft.Data.Analysis.Tests Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -228,7 +228,7 @@ public override double Median()
228228 PrimitiveDataFrameColumn < long > sortIndices = GetAscendingSortIndices ( out Int64DataFrameColumn _ ) ;
229229 long middle = sortIndices . Length / 2 ;
230230 double middleValue = ( double ) Convert . ChangeType ( this [ sortIndices [ middle ] . Value ] . Value , typeof ( double ) ) ;
231- if ( Length % 2 == 0 )
231+ if ( sortIndices . Length % 2 == 0 )
232232 {
233233 double otherMiddleValue = ( double ) Convert . ChangeType ( this [ sortIndices [ middle - 1 ] . Value ] . Value , typeof ( double ) ) ;
234234 return ( middleValue + otherMiddleValue ) / 2 ;
@@ -243,7 +243,7 @@ public override double Mean()
243243 {
244244 if ( Length == 0 )
245245 return 0 ;
246- return ( double ) Convert . ChangeType ( ( T ) Sum ( ) , typeof ( double ) ) / Length ;
246+ return ( double ) Convert . ChangeType ( ( T ) Sum ( ) , typeof ( double ) ) / ( Length - NullCount ) ;
247247 }
248248
249249 protected internal override void Resize ( long length )
Original file line number Diff line number Diff line change @@ -3323,5 +3323,15 @@ public void GetColumnTests()
33233323 Assert . Throws < ArgumentException > ( ( ) => dataFrame . Columns . GetSingleColumn ( "Ushort" ) ) ;
33243324
33253325 }
3326+
3327+ [ Fact ]
3328+ public void TestMeanMedian ( )
3329+ {
3330+ DataFrame df = MakeDataFrameWithNumericColumns ( 10 , true , 0 ) ;
3331+
3332+ Assert . Equal ( 40.0 / 9.0 , df [ "Decimal" ] . Mean ( ) ) ;
3333+ Assert . Equal ( 4 , df [ "Decimal" ] . Median ( ) ) ;
3334+
3335+ }
33263336 }
33273337}
You can’t perform that action at this time.
0 commit comments