diff --git a/src/Microsoft.Data.Analysis/ArrowStringDataFrameColumn.cs b/src/Microsoft.Data.Analysis/ArrowStringDataFrameColumn.cs index 17a38102a2..6cb0103a29 100644 --- a/src/Microsoft.Data.Analysis/ArrowStringDataFrameColumn.cs +++ b/src/Microsoft.Data.Analysis/ArrowStringDataFrameColumn.cs @@ -497,6 +497,10 @@ public PrimitiveDataFrameColumn ElementwiseEquals(string value) public override PrimitiveDataFrameColumn ElementwiseEquals(T value) { + if (value is DataFrameColumn column) + { + return ElementwiseEquals(column); + } return ElementwiseEquals(value.ToString()); } @@ -532,6 +536,10 @@ public PrimitiveDataFrameColumn ElementwiseNotEquals(string value) public override PrimitiveDataFrameColumn ElementwiseNotEquals(T value) { + if (value is DataFrameColumn column) + { + return ElementwiseNotEquals(column); + } return ElementwiseNotEquals(value.ToString()); } diff --git a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.cs b/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.cs index 5fbb83d7ab..c9132d19fb 100644 --- a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.cs +++ b/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.cs @@ -21,7 +21,6 @@ public virtual DataFrameColumn Add(DataFrameColumn column, bool inPlace = false) /// Performs an element wise addition on each value in the column /// public virtual DataFrameColumn Add(T value, bool inPlace = false) - where T : unmanaged { throw new NotImplementedException(); } @@ -30,7 +29,6 @@ public virtual DataFrameColumn Add(T value, bool inPlace = false) /// Performs a reversed element wise addition on each value in the column /// public virtual DataFrameColumn ReverseAdd(T value, bool inPlace = false) - where T : unmanaged { throw new NotImplementedException(); } @@ -44,7 +42,6 @@ public virtual DataFrameColumn Subtract(DataFrameColumn column, bool inPlace = f /// Performs an element wise subtraction on each value in the column /// public virtual DataFrameColumn Subtract(T value, bool inPlace = false) - where T : unmanaged { throw new NotImplementedException(); } @@ -53,7 +50,6 @@ public virtual DataFrameColumn Subtract(T value, bool inPlace = false) /// Performs a reversed element wise subtraction on each value in the column /// public virtual DataFrameColumn ReverseSubtract(T value, bool inPlace = false) - where T : unmanaged { throw new NotImplementedException(); } @@ -67,7 +63,6 @@ public virtual DataFrameColumn Multiply(DataFrameColumn column, bool inPlace = f /// Performs an element wise multiplication on each value in the column /// public virtual DataFrameColumn Multiply(T value, bool inPlace = false) - where T : unmanaged { throw new NotImplementedException(); } @@ -76,7 +71,6 @@ public virtual DataFrameColumn Multiply(T value, bool inPlace = false) /// Performs a reversed element wise multiplication on each value in the column /// public virtual DataFrameColumn ReverseMultiply(T value, bool inPlace = false) - where T : unmanaged { throw new NotImplementedException(); } @@ -90,7 +84,6 @@ public virtual DataFrameColumn Divide(DataFrameColumn column, bool inPlace = fal /// Performs an element wise division on each value in the column /// public virtual DataFrameColumn Divide(T value, bool inPlace = false) - where T : unmanaged { throw new NotImplementedException(); } @@ -99,7 +92,6 @@ public virtual DataFrameColumn Divide(T value, bool inPlace = false) /// Performs a reversed element wise division on each value in the column /// public virtual DataFrameColumn ReverseDivide(T value, bool inPlace = false) - where T : unmanaged { throw new NotImplementedException(); } @@ -113,7 +105,6 @@ public virtual DataFrameColumn Modulo(DataFrameColumn column, bool inPlace = fal /// Performs an element wise modulus operation on each value in the column /// public virtual DataFrameColumn Modulo(T value, bool inPlace = false) - where T : unmanaged { throw new NotImplementedException(); } @@ -122,7 +113,6 @@ public virtual DataFrameColumn Modulo(T value, bool inPlace = false) /// Performs a reversed element wise modulus operation on each value in the column /// public virtual DataFrameColumn ReverseModulo(T value, bool inPlace = false) - where T : unmanaged { throw new NotImplementedException(); } @@ -215,7 +205,6 @@ public virtual PrimitiveDataFrameColumn ElementwiseEquals(DataFrameColumn /// Performs an element wise equals on each value in the column /// public virtual PrimitiveDataFrameColumn ElementwiseEquals(T value) - where T : unmanaged { throw new NotImplementedException(); } @@ -229,7 +218,6 @@ public virtual PrimitiveDataFrameColumn ElementwiseNotEquals(DataFrameColu /// Performs an element wise not-equals on each value in the column /// public virtual PrimitiveDataFrameColumn ElementwiseNotEquals(T value) - where T : unmanaged { throw new NotImplementedException(); } @@ -243,7 +231,6 @@ public virtual PrimitiveDataFrameColumn ElementwiseGreaterThanOrEqual(Data /// Performs an element wise greater than or equal on each value in the column /// public virtual PrimitiveDataFrameColumn ElementwiseGreaterThanOrEqual(T value) - where T : unmanaged { throw new NotImplementedException(); } @@ -257,7 +244,6 @@ public virtual PrimitiveDataFrameColumn ElementwiseLessThanOrEqual(DataFra /// Performs an element wise less than or equal on each value in the column /// public virtual PrimitiveDataFrameColumn ElementwiseLessThanOrEqual(T value) - where T : unmanaged { throw new NotImplementedException(); } @@ -271,7 +257,6 @@ public virtual PrimitiveDataFrameColumn ElementwiseGreaterThan(DataFrameCo /// Performs an element wise greater than on each value in the column /// public virtual PrimitiveDataFrameColumn ElementwiseGreaterThan(T value) - where T : unmanaged { throw new NotImplementedException(); } @@ -285,7 +270,6 @@ public virtual PrimitiveDataFrameColumn ElementwiseLessThan(DataFrameColum /// Performs an element wise less than on each value in the column /// public virtual PrimitiveDataFrameColumn ElementwiseLessThan(T value) - where T : unmanaged { throw new NotImplementedException(); } diff --git a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.tt b/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.tt index 6a05018736..2fcd5c04be 100644 --- a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.tt +++ b/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.tt @@ -30,7 +30,6 @@ namespace Microsoft.Data.Analysis /// <#=method.GetColumnSpecificMethodComments()#> /// public virtual DataFrameColumn <#=method.MethodName#>(T value, bool inPlace = false) - where T : unmanaged <# } #> <# } #> <# if (method.MethodType == MethodType.ComparisonScalar) { #> @@ -38,7 +37,6 @@ namespace Microsoft.Data.Analysis /// <#=method.GetColumnSpecificMethodComments()#> /// public virtual PrimitiveDataFrameColumn <#=method.MethodName#>(T value) - where T : unmanaged <# } #> <# if (method.MethodType == MethodType.Binary) {#> public virtual DataFrameColumn <#=method.MethodName#>(DataFrameColumn column, bool inPlace = false) @@ -67,7 +65,6 @@ namespace Microsoft.Data.Analysis /// <#=method.GetColumnSpecificReverseMethodComments()#> /// public virtual DataFrameColumn Reverse<#=method.MethodName#>(T value, bool inPlace = false) - where T : unmanaged <# } #> { throw new NotImplementedException(); diff --git a/src/Microsoft.Data.Analysis/DecimalConverter.cs b/src/Microsoft.Data.Analysis/DecimalConverter.cs index 741ebf634e..97240969b0 100644 --- a/src/Microsoft.Data.Analysis/DecimalConverter.cs +++ b/src/Microsoft.Data.Analysis/DecimalConverter.cs @@ -5,19 +5,16 @@ namespace Microsoft.Data.Analysis { internal interface IDecimalConverter - where T : struct { decimal GetDecimal(T value); } internal static class DecimalConverter - where T : struct { public static IDecimalConverter Instance { get; } = DecimalConverter.GetDecimalConverter(); } internal static class DecimalConverter { public static IDecimalConverter GetDecimalConverter() - where T : struct { if (typeof(T) == typeof(bool)) { diff --git a/src/Microsoft.Data.Analysis/DoubleConverter.cs b/src/Microsoft.Data.Analysis/DoubleConverter.cs index b5539013cd..399c3ffb25 100644 --- a/src/Microsoft.Data.Analysis/DoubleConverter.cs +++ b/src/Microsoft.Data.Analysis/DoubleConverter.cs @@ -5,19 +5,16 @@ namespace Microsoft.Data.Analysis { internal interface IDoubleConverter - where T : struct { double GetDouble(T value); } internal static class DoubleConverter - where T : struct { public static IDoubleConverter Instance { get; } = DoubleConverter.GetDoubleConverter(); } internal static class DoubleConverter { public static IDoubleConverter GetDoubleConverter() - where T : struct { if (typeof(T) == typeof(bool)) { diff --git a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.cs b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.cs index 03ec75aa54..13cdeda040 100644 --- a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.cs +++ b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace Microsoft.Data.Analysis { @@ -49,6 +50,11 @@ public override DataFrameColumn Add(DataFrameColumn column, bool inPlace = false } public override DataFrameColumn Add(U value, bool inPlace = false) { + DataFrameColumn column = value as DataFrameColumn; + if (column != null) + { + return Add(column, inPlace); + } return AddImplementation(value, inPlace); } public override DataFrameColumn Subtract(DataFrameColumn column, bool inPlace = false) @@ -87,6 +93,11 @@ public override DataFrameColumn Subtract(DataFrameColumn column, bool inPlace = } public override DataFrameColumn Subtract(U value, bool inPlace = false) { + DataFrameColumn column = value as DataFrameColumn; + if (column != null) + { + return Subtract(column, inPlace); + } return SubtractImplementation(value, inPlace); } public override DataFrameColumn Multiply(DataFrameColumn column, bool inPlace = false) @@ -125,6 +136,11 @@ public override DataFrameColumn Multiply(DataFrameColumn column, bool inPlace = } public override DataFrameColumn Multiply(U value, bool inPlace = false) { + DataFrameColumn column = value as DataFrameColumn; + if (column != null) + { + return Multiply(column, inPlace); + } return MultiplyImplementation(value, inPlace); } public override DataFrameColumn Divide(DataFrameColumn column, bool inPlace = false) @@ -163,6 +179,11 @@ public override DataFrameColumn Divide(DataFrameColumn column, bool inPlace = fa } public override DataFrameColumn Divide(U value, bool inPlace = false) { + DataFrameColumn column = value as DataFrameColumn; + if (column != null) + { + return Divide(column, inPlace); + } return DivideImplementation(value, inPlace); } public override DataFrameColumn Modulo(DataFrameColumn column, bool inPlace = false) @@ -201,6 +222,11 @@ public override DataFrameColumn Modulo(DataFrameColumn column, bool inPlace = fa } public override DataFrameColumn Modulo(U value, bool inPlace = false) { + DataFrameColumn column = value as DataFrameColumn; + if (column != null) + { + return Modulo(column, inPlace); + } return ModuloImplementation(value, inPlace); } public override DataFrameColumn And(DataFrameColumn column, bool inPlace = false) @@ -361,6 +387,11 @@ public override PrimitiveDataFrameColumn ElementwiseEquals(DataFrameColumn } public override PrimitiveDataFrameColumn ElementwiseEquals(U value) { + DataFrameColumn column = value as DataFrameColumn; + if (column != null) + { + return ElementwiseEquals(column); + } return ElementwiseEqualsImplementation(value); } public override PrimitiveDataFrameColumn ElementwiseNotEquals(DataFrameColumn column) @@ -399,6 +430,11 @@ public override PrimitiveDataFrameColumn ElementwiseNotEquals(DataFrameCol } public override PrimitiveDataFrameColumn ElementwiseNotEquals(U value) { + DataFrameColumn column = value as DataFrameColumn; + if (column != null) + { + return ElementwiseNotEquals(column); + } return ElementwiseNotEqualsImplementation(value); } public override PrimitiveDataFrameColumn ElementwiseGreaterThanOrEqual(DataFrameColumn column) @@ -437,6 +473,11 @@ public override PrimitiveDataFrameColumn ElementwiseGreaterThanOrEqual(Dat } public override PrimitiveDataFrameColumn ElementwiseGreaterThanOrEqual(U value) { + DataFrameColumn column = value as DataFrameColumn; + if (column != null) + { + return ElementwiseGreaterThanOrEqual(column); + } return ElementwiseGreaterThanOrEqualImplementation(value); } public override PrimitiveDataFrameColumn ElementwiseLessThanOrEqual(DataFrameColumn column) @@ -475,6 +516,11 @@ public override PrimitiveDataFrameColumn ElementwiseLessThanOrEqual(DataFr } public override PrimitiveDataFrameColumn ElementwiseLessThanOrEqual(U value) { + DataFrameColumn column = value as DataFrameColumn; + if (column != null) + { + return ElementwiseLessThanOrEqual(column); + } return ElementwiseLessThanOrEqualImplementation(value); } public override PrimitiveDataFrameColumn ElementwiseGreaterThan(DataFrameColumn column) @@ -513,6 +559,11 @@ public override PrimitiveDataFrameColumn ElementwiseGreaterThan(DataFrameC } public override PrimitiveDataFrameColumn ElementwiseGreaterThan(U value) { + DataFrameColumn column = value as DataFrameColumn; + if (column != null) + { + return ElementwiseGreaterThan(column); + } return ElementwiseGreaterThanImplementation(value); } public override PrimitiveDataFrameColumn ElementwiseLessThan(DataFrameColumn column) @@ -551,6 +602,11 @@ public override PrimitiveDataFrameColumn ElementwiseLessThan(DataFrameColu } public override PrimitiveDataFrameColumn ElementwiseLessThan(U value) { + DataFrameColumn column = value as DataFrameColumn; + if (column != null) + { + return ElementwiseLessThan(column); + } return ElementwiseLessThanImplementation(value); } @@ -635,7 +691,6 @@ internal DataFrameColumn AddImplementation(PrimitiveDataFrameColumn column } } internal DataFrameColumn AddImplementation(U value, bool inPlace) - where U : unmanaged { switch (typeof(T)) { @@ -649,9 +704,9 @@ internal DataFrameColumn AddImplementation(U value, bool inPlace) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.Add(value); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); + newColumn._columnContainer.Add(Unsafe.As(ref value)); return newColumn; } else @@ -682,9 +737,9 @@ internal DataFrameColumn AddImplementation(U value, bool inPlace) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.Add(value); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); + newColumn._columnContainer.Add(Unsafe.As(ref value)); return newColumn; } else @@ -791,7 +846,6 @@ internal DataFrameColumn SubtractImplementation(PrimitiveDataFrameColumn c } } internal DataFrameColumn SubtractImplementation(U value, bool inPlace) - where U : unmanaged { switch (typeof(T)) { @@ -805,9 +859,9 @@ internal DataFrameColumn SubtractImplementation(U value, bool inPlace) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.Subtract(value); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); + newColumn._columnContainer.Subtract(Unsafe.As(ref value)); return newColumn; } else @@ -838,9 +892,9 @@ internal DataFrameColumn SubtractImplementation(U value, bool inPlace) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.Subtract(value); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); + newColumn._columnContainer.Subtract(Unsafe.As(ref value)); return newColumn; } else @@ -947,7 +1001,6 @@ internal DataFrameColumn MultiplyImplementation(PrimitiveDataFrameColumn c } } internal DataFrameColumn MultiplyImplementation(U value, bool inPlace) - where U : unmanaged { switch (typeof(T)) { @@ -961,9 +1014,9 @@ internal DataFrameColumn MultiplyImplementation(U value, bool inPlace) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.Multiply(value); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); + newColumn._columnContainer.Multiply(Unsafe.As(ref value)); return newColumn; } else @@ -994,9 +1047,9 @@ internal DataFrameColumn MultiplyImplementation(U value, bool inPlace) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.Multiply(value); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); + newColumn._columnContainer.Multiply(Unsafe.As(ref value)); return newColumn; } else @@ -1103,7 +1156,6 @@ internal DataFrameColumn DivideImplementation(PrimitiveDataFrameColumn col } } internal DataFrameColumn DivideImplementation(U value, bool inPlace) - where U : unmanaged { switch (typeof(T)) { @@ -1117,9 +1169,9 @@ internal DataFrameColumn DivideImplementation(U value, bool inPlace) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.Divide(value); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); + newColumn._columnContainer.Divide(Unsafe.As(ref value)); return newColumn; } else @@ -1150,9 +1202,9 @@ internal DataFrameColumn DivideImplementation(U value, bool inPlace) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.Divide(value); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); + newColumn._columnContainer.Divide(Unsafe.As(ref value)); return newColumn; } else @@ -1259,7 +1311,6 @@ internal DataFrameColumn ModuloImplementation(PrimitiveDataFrameColumn col } } internal DataFrameColumn ModuloImplementation(U value, bool inPlace) - where U : unmanaged { switch (typeof(T)) { @@ -1273,9 +1324,9 @@ internal DataFrameColumn ModuloImplementation(U value, bool inPlace) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.Modulo(value); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); + newColumn._columnContainer.Modulo(Unsafe.As(ref value)); return newColumn; } else @@ -1306,9 +1357,9 @@ internal DataFrameColumn ModuloImplementation(U value, bool inPlace) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.Modulo(value); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); + newColumn._columnContainer.Modulo(Unsafe.As(ref value)); return newColumn; } else @@ -1369,7 +1420,6 @@ internal DataFrameColumn AndImplementation(PrimitiveDataFrameColumn column } } internal PrimitiveDataFrameColumn AndImplementation(U value, bool inPlace) - where U : unmanaged { switch (typeof(T)) { @@ -1378,9 +1428,9 @@ internal PrimitiveDataFrameColumn AndImplementation(U value, bool inPla { throw new NotSupportedException(); } - PrimitiveDataFrameColumn typedColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn retColumn = inPlace ? typedColumn : typedColumn.Clone(); - retColumn._columnContainer.And(value); + PrimitiveDataFrameColumn typedColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn retColumn = inPlace ? typedColumn : typedColumn.Clone(); + retColumn._columnContainer.And(Unsafe.As(ref value)); return retColumn as PrimitiveDataFrameColumn; case Type byteType when byteType == typeof(byte): case Type charType when charType == typeof(char): @@ -1433,7 +1483,6 @@ internal DataFrameColumn OrImplementation(PrimitiveDataFrameColumn column, } } internal PrimitiveDataFrameColumn OrImplementation(U value, bool inPlace) - where U : unmanaged { switch (typeof(T)) { @@ -1442,9 +1491,9 @@ internal PrimitiveDataFrameColumn OrImplementation(U value, bool inPlac { throw new NotSupportedException(); } - PrimitiveDataFrameColumn typedColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn retColumn = inPlace ? typedColumn : typedColumn.Clone(); - retColumn._columnContainer.Or(value); + PrimitiveDataFrameColumn typedColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn retColumn = inPlace ? typedColumn : typedColumn.Clone(); + retColumn._columnContainer.Or(Unsafe.As(ref value)); return retColumn as PrimitiveDataFrameColumn; case Type byteType when byteType == typeof(byte): case Type charType when charType == typeof(char): @@ -1497,7 +1546,6 @@ internal DataFrameColumn XorImplementation(PrimitiveDataFrameColumn column } } internal PrimitiveDataFrameColumn XorImplementation(U value, bool inPlace) - where U : unmanaged { switch (typeof(T)) { @@ -1506,9 +1554,9 @@ internal PrimitiveDataFrameColumn XorImplementation(U value, bool inPla { throw new NotSupportedException(); } - PrimitiveDataFrameColumn typedColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn retColumn = inPlace ? typedColumn : typedColumn.Clone(); - retColumn._columnContainer.Xor(value); + PrimitiveDataFrameColumn typedColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn retColumn = inPlace ? typedColumn : typedColumn.Clone(); + retColumn._columnContainer.Xor(Unsafe.As(ref value)); return retColumn as PrimitiveDataFrameColumn; case Type byteType when byteType == typeof(byte): case Type charType when charType == typeof(char): @@ -1730,7 +1778,6 @@ internal PrimitiveDataFrameColumn ElementwiseEqualsImplementation(Primi } } internal PrimitiveDataFrameColumn ElementwiseEqualsImplementation(U value) - where U : unmanaged { switch (typeof(T)) { @@ -1740,7 +1787,7 @@ internal PrimitiveDataFrameColumn ElementwiseEqualsImplementation(U val throw new NotSupportedException(); } PrimitiveDataFrameColumn retColumn = CloneAsBoolColumn(); - (this as PrimitiveDataFrameColumn)._columnContainer.ElementwiseEquals(value, retColumn._columnContainer); + (this as PrimitiveDataFrameColumn)._columnContainer.ElementwiseEquals(Unsafe.As(ref value), retColumn._columnContainer); return retColumn; case Type decimalType when decimalType == typeof(decimal): if (typeof(U) == typeof(bool)) @@ -1750,9 +1797,9 @@ internal PrimitiveDataFrameColumn ElementwiseEqualsImplementation(U val if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn primitiveColumn = this; PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); - primitiveColumn._columnContainer.ElementwiseEquals(value, newColumn._columnContainer); + primitiveColumn._columnContainer.ElementwiseEquals(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; } else @@ -1780,9 +1827,9 @@ internal PrimitiveDataFrameColumn ElementwiseEqualsImplementation(U val if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn primitiveColumn = this; PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); - primitiveColumn._columnContainer.ElementwiseEquals(value, newColumn._columnContainer); + primitiveColumn._columnContainer.ElementwiseEquals(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; } else @@ -1888,7 +1935,6 @@ internal PrimitiveDataFrameColumn ElementwiseNotEqualsImplementation(Pr } } internal PrimitiveDataFrameColumn ElementwiseNotEqualsImplementation(U value) - where U : unmanaged { switch (typeof(T)) { @@ -1898,7 +1944,7 @@ internal PrimitiveDataFrameColumn ElementwiseNotEqualsImplementation(U throw new NotSupportedException(); } PrimitiveDataFrameColumn retColumn = CloneAsBoolColumn(); - (this as PrimitiveDataFrameColumn)._columnContainer.ElementwiseNotEquals(value, retColumn._columnContainer); + (this as PrimitiveDataFrameColumn)._columnContainer.ElementwiseNotEquals(Unsafe.As(ref value), retColumn._columnContainer); return retColumn; case Type decimalType when decimalType == typeof(decimal): if (typeof(U) == typeof(bool)) @@ -1908,9 +1954,9 @@ internal PrimitiveDataFrameColumn ElementwiseNotEqualsImplementation(U if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn primitiveColumn = this; PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); - primitiveColumn._columnContainer.ElementwiseNotEquals(value, newColumn._columnContainer); + primitiveColumn._columnContainer.ElementwiseNotEquals(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; } else @@ -1938,9 +1984,9 @@ internal PrimitiveDataFrameColumn ElementwiseNotEqualsImplementation(U if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn primitiveColumn = this; PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); - primitiveColumn._columnContainer.ElementwiseNotEquals(value, newColumn._columnContainer); + primitiveColumn._columnContainer.ElementwiseNotEquals(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; } else @@ -2040,7 +2086,6 @@ internal PrimitiveDataFrameColumn ElementwiseGreaterThanOrEqualImplementat } } internal PrimitiveDataFrameColumn ElementwiseGreaterThanOrEqualImplementation(U value) - where U : unmanaged { switch (typeof(T)) { @@ -2054,9 +2099,9 @@ internal PrimitiveDataFrameColumn ElementwiseGreaterThanOrEqualImplementat if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn primitiveColumn = this; PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); - primitiveColumn._columnContainer.ElementwiseGreaterThanOrEqual(value, newColumn._columnContainer); + primitiveColumn._columnContainer.ElementwiseGreaterThanOrEqual(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; } else @@ -2084,9 +2129,9 @@ internal PrimitiveDataFrameColumn ElementwiseGreaterThanOrEqualImplementat if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn primitiveColumn = this; PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); - primitiveColumn._columnContainer.ElementwiseGreaterThanOrEqual(value, newColumn._columnContainer); + primitiveColumn._columnContainer.ElementwiseGreaterThanOrEqual(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; } else @@ -2186,7 +2231,6 @@ internal PrimitiveDataFrameColumn ElementwiseLessThanOrEqualImplementation } } internal PrimitiveDataFrameColumn ElementwiseLessThanOrEqualImplementation(U value) - where U : unmanaged { switch (typeof(T)) { @@ -2200,9 +2244,9 @@ internal PrimitiveDataFrameColumn ElementwiseLessThanOrEqualImplementation if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn primitiveColumn = this; PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); - primitiveColumn._columnContainer.ElementwiseLessThanOrEqual(value, newColumn._columnContainer); + primitiveColumn._columnContainer.ElementwiseLessThanOrEqual(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; } else @@ -2230,9 +2274,9 @@ internal PrimitiveDataFrameColumn ElementwiseLessThanOrEqualImplementation if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn primitiveColumn = this; PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); - primitiveColumn._columnContainer.ElementwiseLessThanOrEqual(value, newColumn._columnContainer); + primitiveColumn._columnContainer.ElementwiseLessThanOrEqual(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; } else @@ -2332,7 +2376,6 @@ internal PrimitiveDataFrameColumn ElementwiseGreaterThanImplementation( } } internal PrimitiveDataFrameColumn ElementwiseGreaterThanImplementation(U value) - where U : unmanaged { switch (typeof(T)) { @@ -2346,9 +2389,9 @@ internal PrimitiveDataFrameColumn ElementwiseGreaterThanImplementation( if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn primitiveColumn = this; PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); - primitiveColumn._columnContainer.ElementwiseGreaterThan(value, newColumn._columnContainer); + primitiveColumn._columnContainer.ElementwiseGreaterThan(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; } else @@ -2376,9 +2419,9 @@ internal PrimitiveDataFrameColumn ElementwiseGreaterThanImplementation( if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn primitiveColumn = this; PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); - primitiveColumn._columnContainer.ElementwiseGreaterThan(value, newColumn._columnContainer); + primitiveColumn._columnContainer.ElementwiseGreaterThan(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; } else @@ -2478,7 +2521,6 @@ internal PrimitiveDataFrameColumn ElementwiseLessThanImplementation(Pri } } internal PrimitiveDataFrameColumn ElementwiseLessThanImplementation(U value) - where U : unmanaged { switch (typeof(T)) { @@ -2492,9 +2534,9 @@ internal PrimitiveDataFrameColumn ElementwiseLessThanImplementation(U v if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn primitiveColumn = this; PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); - primitiveColumn._columnContainer.ElementwiseLessThan(value, newColumn._columnContainer); + primitiveColumn._columnContainer.ElementwiseLessThan(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; } else @@ -2522,9 +2564,9 @@ internal PrimitiveDataFrameColumn ElementwiseLessThanImplementation(U v if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn primitiveColumn = this; PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); - primitiveColumn._columnContainer.ElementwiseLessThan(value, newColumn._columnContainer); + primitiveColumn._columnContainer.ElementwiseLessThan(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; } else diff --git a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.tt b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.tt index 29c9b8d95e..8dee5658d3 100644 --- a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.tt +++ b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.tt @@ -13,6 +13,7 @@ using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace Microsoft.Data.Analysis { @@ -54,8 +55,22 @@ namespace Microsoft.Data.Analysis <# } #> { <# if (method.MethodType == MethodType.BinaryScalar) {#> +<# if (method.IsBitwise == true) { #> return <#=method.MethodName#>Implementation(value, inPlace); +<# } else { #> + DataFrameColumn column = value as DataFrameColumn; + if (column != null) + { + return <#=method.MethodName#>(column, inPlace); + } + return <#=method.MethodName#>Implementation(value, inPlace); +<# } #> <# } else {#> + DataFrameColumn column = value as DataFrameColumn; + if (column != null) + { + return <#=method.MethodName#>(column); + } return <#=method.MethodName#>Implementation(value); <# } #> } @@ -79,7 +94,6 @@ namespace Microsoft.Data.Analysis <# } else {#> internal PrimitiveDataFrameColumn <#=method.MethodName#>Implementation(U value) <# } #> - where U : unmanaged <# } #> <# if (method.MethodType == MethodType.Binary || method.MethodType == MethodType.Comparison) {#> <# if (method.MethodType == MethodType.Binary) {#> @@ -126,9 +140,9 @@ namespace Microsoft.Data.Analysis throw new NotSupportedException(); } <# if (method.MethodType == MethodType.BinaryScalar) {#> - PrimitiveDataFrameColumn typedColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn retColumn = <#=GenerateInPlaceStatement("typedColumn", "typedColumn.Clone()")#>; - retColumn._columnContainer.<#=method.MethodName#>(value); + PrimitiveDataFrameColumn typedColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn retColumn = <#=GenerateInPlaceStatement("typedColumn", "typedColumn.Clone()")#>; + retColumn._columnContainer.<#=method.MethodName#>(Unsafe.As(ref value)); return retColumn as PrimitiveDataFrameColumn; <# } else { #> PrimitiveDataFrameColumn typedColumn = this as PrimitiveDataFrameColumn; @@ -161,7 +175,7 @@ namespace Microsoft.Data.Analysis <# if (method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.Comparison) { #> PrimitiveDataFrameColumn retColumn = CloneAsBoolColumn(); <# if (method.MethodType == MethodType.ComparisonScalar) { #> - (this as PrimitiveDataFrameColumn)._columnContainer.<#=method.MethodName#>(value, retColumn._columnContainer); + (this as PrimitiveDataFrameColumn)._columnContainer.<#=method.MethodName#>(Unsafe.As(ref value), retColumn._columnContainer); <# } else { #> (this as PrimitiveDataFrameColumn)._columnContainer.<#=method.MethodName#>(column._columnContainer, retColumn._columnContainer); <# } #> @@ -185,23 +199,27 @@ namespace Microsoft.Data.Analysis if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; <# if (method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.Comparison) { #> - PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); <# if (method.MethodType == MethodType.ComparisonScalar) { #> - primitiveColumn._columnContainer.<#=method.MethodName#>(value, newColumn._columnContainer); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); + primitiveColumn._columnContainer.<#=method.MethodName#>(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; <# } else { #> + PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); primitiveColumn._columnContainer.<#=method.MethodName#>(column._columnContainer, newColumn._columnContainer); return newColumn; <# } #> <# } else if (method.IsBitwise == true ) { #> throw new NotSupportedException(); <# } else if (method.MethodType == MethodType.BinaryScalar ) { #> - PrimitiveDataFrameColumn newColumn = <#=GenerateInPlaceStatement("primitiveColumn", "primitiveColumn.Clone()")#>; - newColumn._columnContainer.<#=method.MethodName#>(value); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = <#=GenerateInPlaceStatement("primitiveColumn", "primitiveColumn.Clone()")#>; + newColumn._columnContainer.<#=method.MethodName#>(Unsafe.As(ref value)); return newColumn; <# } else { #> + PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; PrimitiveDataFrameColumn newColumn = <#=GenerateInPlaceStatement("primitiveColumn", "primitiveColumn.Clone()")#>; newColumn._columnContainer.<#=method.MethodName#>(column._columnContainer); return newColumn; @@ -264,23 +282,27 @@ namespace Microsoft.Data.Analysis if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; <# if (method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.Comparison) { #> - PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); <# if (method.MethodType == MethodType.ComparisonScalar) { #> - primitiveColumn._columnContainer.<#=method.MethodName#>(value, newColumn._columnContainer); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); + primitiveColumn._columnContainer.<#=method.MethodName#>(Unsafe.As(ref value), newColumn._columnContainer); return newColumn; <# } else { #> + PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; + PrimitiveDataFrameColumn newColumn = CloneAsBoolColumn(); primitiveColumn._columnContainer.<#=method.MethodName#>(column._columnContainer, newColumn._columnContainer); return newColumn; <# } #> <# } else if (method.IsBitwise == true ) { #> throw new NotSupportedException(); <# } else if (method.MethodType == MethodType.BinaryScalar ) { #> - PrimitiveDataFrameColumn newColumn = <#=GenerateInPlaceStatement("primitiveColumn", "primitiveColumn.Clone()")#>; - newColumn._columnContainer.<#=method.MethodName#>(value); + PrimitiveDataFrameColumn primitiveColumn = this; + PrimitiveDataFrameColumn newColumn = <#=GenerateInPlaceStatement("primitiveColumn", "primitiveColumn.Clone()")#>; + newColumn._columnContainer.<#=method.MethodName#>(Unsafe.As(ref value)); return newColumn; <# } else { #> + PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; PrimitiveDataFrameColumn newColumn = <#=GenerateInPlaceStatement("primitiveColumn", "primitiveColumn.Clone()")#>; newColumn._columnContainer.<#=method.MethodName#>(column._columnContainer); return newColumn; diff --git a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.ReversedBinaryOperations.cs b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.ReversedBinaryOperations.cs index 73e338fd40..d5309da3d0 100644 --- a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.ReversedBinaryOperations.cs +++ b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.ReversedBinaryOperations.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace Microsoft.Data.Analysis { @@ -28,9 +29,8 @@ public override DataFrameColumn ReverseAdd(U value, bool inPlace = false) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.ReverseAdd(value); + PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); + newColumn._columnContainer.ReverseAdd(Unsafe.As(ref value)); return newColumn; } else @@ -61,9 +61,8 @@ public override DataFrameColumn ReverseAdd(U value, bool inPlace = false) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.ReverseAdd(value); + PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); + newColumn._columnContainer.ReverseAdd(Unsafe.As(ref value)); return newColumn; } else @@ -103,9 +102,8 @@ public override DataFrameColumn ReverseSubtract(U value, bool inPlace = false if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.ReverseSubtract(value); + PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); + newColumn._columnContainer.ReverseSubtract(Unsafe.As(ref value)); return newColumn; } else @@ -136,9 +134,8 @@ public override DataFrameColumn ReverseSubtract(U value, bool inPlace = false if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.ReverseSubtract(value); + PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); + newColumn._columnContainer.ReverseSubtract(Unsafe.As(ref value)); return newColumn; } else @@ -178,9 +175,8 @@ public override DataFrameColumn ReverseMultiply(U value, bool inPlace = false if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.ReverseMultiply(value); + PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); + newColumn._columnContainer.ReverseMultiply(Unsafe.As(ref value)); return newColumn; } else @@ -211,9 +207,8 @@ public override DataFrameColumn ReverseMultiply(U value, bool inPlace = false if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.ReverseMultiply(value); + PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); + newColumn._columnContainer.ReverseMultiply(Unsafe.As(ref value)); return newColumn; } else @@ -253,9 +248,8 @@ public override DataFrameColumn ReverseDivide(U value, bool inPlace = false) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.ReverseDivide(value); + PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); + newColumn._columnContainer.ReverseDivide(Unsafe.As(ref value)); return newColumn; } else @@ -286,9 +280,8 @@ public override DataFrameColumn ReverseDivide(U value, bool inPlace = false) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.ReverseDivide(value); + PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); + newColumn._columnContainer.ReverseDivide(Unsafe.As(ref value)); return newColumn; } else @@ -328,9 +321,8 @@ public override DataFrameColumn ReverseModulo(U value, bool inPlace = false) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.ReverseModulo(value); + PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); + newColumn._columnContainer.ReverseModulo(Unsafe.As(ref value)); return newColumn; } else @@ -361,9 +353,8 @@ public override DataFrameColumn ReverseModulo(U value, bool inPlace = false) if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.ReverseModulo(value); + PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); + newColumn._columnContainer.ReverseModulo(Unsafe.As(ref value)); return newColumn; } else diff --git a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.ReversedBinaryOperations.tt b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.ReversedBinaryOperations.tt index 64917994cc..61bdd71799 100644 --- a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.ReversedBinaryOperations.tt +++ b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.ReversedBinaryOperations.tt @@ -13,6 +13,7 @@ using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace Microsoft.Data.Analysis { @@ -52,9 +53,8 @@ namespace Microsoft.Data.Analysis if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.Reverse<#=method.MethodName#>(value); + PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); + newColumn._columnContainer.Reverse<#=method.MethodName#>(Unsafe.As(ref value)); return newColumn; } else @@ -81,9 +81,8 @@ namespace Microsoft.Data.Analysis if (typeof(U) == typeof(T)) { // No conversions - PrimitiveDataFrameColumn primitiveColumn = this as PrimitiveDataFrameColumn; - PrimitiveDataFrameColumn newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone(); - newColumn._columnContainer.Reverse<#=method.MethodName#>(value); + PrimitiveDataFrameColumn newColumn = inPlace ? this : Clone(); + newColumn._columnContainer.Reverse<#=method.MethodName#>(Unsafe.As(ref value)); return newColumn; } else diff --git a/src/Microsoft.Data.Analysis/StringDataFrameColumn.BinaryOperations.cs b/src/Microsoft.Data.Analysis/StringDataFrameColumn.BinaryOperations.cs index d90118b193..ffc387e211 100644 --- a/src/Microsoft.Data.Analysis/StringDataFrameColumn.BinaryOperations.cs +++ b/src/Microsoft.Data.Analysis/StringDataFrameColumn.BinaryOperations.cs @@ -103,6 +103,10 @@ public PrimitiveDataFrameColumn ElementwiseEquals(string value) public override PrimitiveDataFrameColumn ElementwiseEquals(T value) { + if (value is DataFrameColumn column) + { + return ElementwiseEquals(column); + } return ElementwiseEquals(value.ToString()); } @@ -137,6 +141,10 @@ public override PrimitiveDataFrameColumn ElementwiseNotEquals(DataFrameCol public override PrimitiveDataFrameColumn ElementwiseNotEquals(T value) { + if (value is DataFrameColumn column) + { + return ElementwiseNotEquals(column); + } return ElementwiseNotEquals(value.ToString()); } } diff --git a/tests/Microsoft.Data.Analysis.Tests/DataFrameTests.cs b/tests/Microsoft.Data.Analysis.Tests/DataFrameTests.cs index b5ddefddd5..8fc3eca52b 100644 --- a/tests/Microsoft.Data.Analysis.Tests/DataFrameTests.cs +++ b/tests/Microsoft.Data.Analysis.Tests/DataFrameTests.cs @@ -460,6 +460,10 @@ public void TestBinaryOperationsOnArrowStringColumn() newCol = stringColumn.ElementwiseEquals(stringColumnCopy); Assert.True(newCol.All()); + DataFrameColumn stringColumnCopyAsBaseColumn = stringColumnCopy; + newCol = stringColumn.ElementwiseEquals(stringColumnCopyAsBaseColumn); + Assert.True(newCol.All()); + newCol = stringColumn.ElementwiseNotEquals(5); Assert.Equal(true, newCol[0]); Assert.Equal(false, newCol[5]); @@ -475,6 +479,9 @@ public void TestBinaryOperationsOnArrowStringColumn() newCol = stringColumn.ElementwiseNotEquals(stringColumnCopy); Assert.False(newCol.All()); + + newCol = stringColumn.ElementwiseNotEquals(stringColumnCopyAsBaseColumn); + Assert.False(newCol.All()); } [Fact] @@ -497,11 +504,16 @@ public void TestBinaryOperationsOnStringColumn() Assert.Equal(true, newCol[5]); Assert.Equal(true, newCol[0]); + StringDataFrameColumn typedStringColumn = stringColumn as StringDataFrameColumn; + StringDataFrameColumn typedStringColumnCopy = stringColumnCopy as StringDataFrameColumn; + newCol = typedStringColumn.ElementwiseEquals(typedStringColumnCopy); + Assert.True(newCol.All()); + newCol = stringColumn.ElementwiseNotEquals(5); Assert.Equal(false, newCol[5]); Assert.Equal(true, newCol[0]); - newCol = (stringColumn as StringDataFrameColumn).ElementwiseNotEquals("5"); + newCol = typedStringColumn.ElementwiseNotEquals("5"); Assert.Equal(false, newCol[5]); Assert.Equal(true, newCol[0]); @@ -509,7 +521,9 @@ public void TestBinaryOperationsOnStringColumn() Assert.Equal(false, newCol[5]); Assert.Equal(false, newCol[0]); - StringDataFrameColumn typedStringColumn = stringColumn as StringDataFrameColumn; + newCol = typedStringColumn.ElementwiseNotEquals(typedStringColumnCopy); + Assert.False(newCol.All()); + newCol = typedStringColumn.Add("suffix"); for (int i = 0; i < newCol.Length; i++) { @@ -657,6 +671,9 @@ public void TestBinaryOperationsOnColumns() PrimitiveDataFrameColumn column = new PrimitiveDataFrameColumn("Int", Enumerable.Range(0, 10)); Assert.ThrowsAny(() => column.Add(5.5, inPlace: true)); Assert.ThrowsAny(() => column.ReverseAdd(5.5, inPlace: true)); + string str = "A String"; + Assert.ThrowsAny(() => column.Add(str, inPlace: true)); + Assert.ThrowsAny(() => column.ReverseAdd(str, inPlace: true)); } [Fact]