Skip to content

Commit 4f0afc3

Browse files
authored
Fix DataFrame Null Math (#6661)
* Fix math and update templates to match generated files. * Add Tests * Fix test * Same issue? * Test and Fix Median and Mean * Update Cumulative handling of nulls based on DataFrame documentation
1 parent 247f3a0 commit 4f0afc3

10 files changed

+907
-173
lines changed

src/Microsoft.Data.Analysis/DataFrame.BinaryOperators.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Microsoft.Data.Analysis
1818
{
1919
public partial class DataFrame
2020
{
21-
#pragma warning disable 1591
21+
#pragma warning disable 1591
2222
<# foreach (MethodConfiguration method in methodConfiguration) { #>
2323
<# if (method.MethodType == MethodType.BinaryScalar) { #>
2424
<# if (method.IsBitwise == true) { #>
@@ -32,7 +32,7 @@ namespace Microsoft.Data.Analysis
3232
{
3333
return df.<#=method.MethodName#>(value);
3434
}
35-
35+
3636
public static DataFrame operator <#=method.Operator#>(<#=type.TypeName#> value, DataFrame df)
3737
{
3838
return df.Reverse<#=method.MethodName#>(value);

src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperators.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Microsoft.Data.Analysis
1818
{
1919
public abstract partial class DataFrameColumn
2020
{
21-
#pragma warning disable 1591
21+
#pragma warning disable 1591
2222
<# foreach (MethodConfiguration method in methodConfiguration) { #>
2323
<# if (method.MethodType == MethodType.BinaryScalar) { #>
2424
<# if (method.IsBitwise == true) { #>

src/Microsoft.Data.Analysis/PrimitiveColumnContainer.BinaryOperations.tt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ namespace Microsoft.Data.Analysis
1818
{
1919
<# foreach (MethodConfiguration method in methodConfiguration) { #>
2020
<# if (method.MethodType == MethodType.Comparison || method.MethodType == MethodType.ComparisonScalar) { #>
21-
public <#= method.GetSingleArgumentMethodSignature("PrimitiveColumnContainer", "T") #>
22-
{
21+
public <#= method.GetSingleArgumentMethodSignature("PrimitiveColumnContainer", "T") #>
22+
{
2323
<# if (method.MethodType == MethodType.ComparisonScalar ) { #>
2424
PrimitiveDataFrameColumnArithmetic<T>.Instance.<#=method.MethodName#>(this, scalar, ret);
2525
<# } else { #>
2626
PrimitiveDataFrameColumnArithmetic<T>.Instance.<#=method.MethodName#>(this, right, ret);
2727
<# } #>
2828
return this;
29-
}
29+
}
3030

3131
<# } else { #>
3232
public <#= method.GetSingleArgumentMethodSignature("PrimitiveColumnContainer", "T")#>
@@ -45,11 +45,11 @@ namespace Microsoft.Data.Analysis
4545
<# } #>
4646
<# foreach (MethodConfiguration method in methodConfiguration) { #>
4747
<# if (method.MethodType == MethodType.BinaryScalar) { #>
48-
public PrimitiveColumnContainer<T> Reverse<#=method.MethodName#>(T scalar)
49-
{
48+
public PrimitiveColumnContainer<T> Reverse<#=method.MethodName#>(T scalar)
49+
{
5050
PrimitiveDataFrameColumnArithmetic<T>.Instance.<#=method.MethodName#>(scalar, this);
5151
return this;
52-
}
52+
}
5353
<# } #>
5454
<# } #>
5555
}

src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)