diff --git a/eng/Versions.props b/eng/Versions.props index bf1e608240..2424bf129c 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -30,7 +30,7 @@ 6.0.1 4.7.1 - 2.0.0 + 11.0.0 3.19.6 2.3.1 3.3.0 diff --git a/src/Microsoft.Data.Analysis/AssemblyAttributes.cs b/src/Microsoft.Data.Analysis/AssemblyAttributes.cs new file mode 100644 index 0000000000..b9a8a4daa9 --- /dev/null +++ b/src/Microsoft.Data.Analysis/AssemblyAttributes.cs @@ -0,0 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Runtime.Versioning; + +[assembly: RequiresPreviewFeatures] diff --git a/src/Microsoft.Data.Analysis/BooleanDataFrameColumn.cs b/src/Microsoft.Data.Analysis/BooleanDataFrameColumn.cs deleted file mode 100644 index cc9d6e5a6e..0000000000 --- a/src/Microsoft.Data.Analysis/BooleanDataFrameColumn.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.Data.Analysis -{ - public partial class BooleanDataFrameColumn : PrimitiveDataFrameColumn - { - public BooleanDataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public BooleanDataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public BooleanDataFrameColumn(string name, long length = 0) : base(name, length) { } - - public BooleanDataFrameColumn(string name, ReadOnlyMemory buffer, ReadOnlyMemory nullBitMap, int length = 0, int nullCount = 0) : base(name, buffer, nullBitMap, length, nullCount) { } - - internal BooleanDataFrameColumn(string name, PrimitiveColumnContainer values) : base(name, values) { } - - protected override PrimitiveDataFrameColumn CreateNewColumn(string name, long length = 0) - { - return new BooleanDataFrameColumn(name, length); - } - - internal override PrimitiveDataFrameColumn CreateNewColumn(string name, PrimitiveColumnContainer container) - { - return new BooleanDataFrameColumn(name, container); - } - } -} diff --git a/src/Microsoft.Data.Analysis/ByteDataFrameColumn.cs b/src/Microsoft.Data.Analysis/ByteDataFrameColumn.cs deleted file mode 100644 index d341e2cd16..0000000000 --- a/src/Microsoft.Data.Analysis/ByteDataFrameColumn.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.Data.Analysis -{ - public partial class ByteDataFrameColumn : PrimitiveDataFrameColumn - { - public ByteDataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public ByteDataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public ByteDataFrameColumn(string name, long length = 0) : base(name, length) { } - - public ByteDataFrameColumn(string name, ReadOnlyMemory buffer, ReadOnlyMemory nullBitMap, int length = 0, int nullCount = 0) : base(name, buffer, nullBitMap, length, nullCount) { } - - internal ByteDataFrameColumn(string name, PrimitiveColumnContainer values) : base(name, values) { } - - protected override PrimitiveDataFrameColumn CreateNewColumn(string name, long length = 0) - { - return new ByteDataFrameColumn(name, length); - } - - internal override PrimitiveDataFrameColumn CreateNewColumn(string name, PrimitiveColumnContainer container) - { - return new ByteDataFrameColumn(name, container); - } - } -} diff --git a/src/Microsoft.Data.Analysis/CharDataFrameColumn.cs b/src/Microsoft.Data.Analysis/CharDataFrameColumn.cs deleted file mode 100644 index 8abbc3f335..0000000000 --- a/src/Microsoft.Data.Analysis/CharDataFrameColumn.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.Data.Analysis -{ - public partial class CharDataFrameColumn : PrimitiveDataFrameColumn - { - public CharDataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public CharDataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public CharDataFrameColumn(string name, long length = 0) : base(name, length) { } - - public CharDataFrameColumn(string name, ReadOnlyMemory buffer, ReadOnlyMemory nullBitMap, int length = 0, int nullCount = 0) : base(name, buffer, nullBitMap, length, nullCount) { } - - internal CharDataFrameColumn(string name, PrimitiveColumnContainer values) : base(name, values) { } - - protected override PrimitiveDataFrameColumn CreateNewColumn(string name, long length = 0) - { - return new CharDataFrameColumn(name, length); - } - - internal override PrimitiveDataFrameColumn CreateNewColumn(string name, PrimitiveColumnContainer container) - { - return new CharDataFrameColumn(name, container); - } - } -} diff --git a/src/Microsoft.Data.Analysis/ColumnArithmeticTemplate.ttinclude b/src/Microsoft.Data.Analysis/ColumnArithmeticTemplate.ttinclude deleted file mode 100644 index bb31da6a94..0000000000 --- a/src/Microsoft.Data.Analysis/ColumnArithmeticTemplate.ttinclude +++ /dev/null @@ -1,459 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#+ - public class TypeConfiguration - { - public TypeConfiguration(string typeName, string classPrefix = null, string oneLiteral = "1", string zeroLiteral = "0", bool supportsNumeric = true, bool supportsBitwise = true, IEnumerable unsupportedMethods = null) - { - TypeName = typeName; - ClassPrefix = classPrefix ?? char.ToUpper(typeName[0]) + typeName.Substring(1); - OneLiteral = oneLiteral; - ZeroLiteral = zeroLiteral; - SupportsNumeric = supportsNumeric; - SupportsBitwise = supportsBitwise; - UnsupportedMethods = new HashSet(unsupportedMethods ?? Enumerable.Empty()); - } - - public string TypeName { get; } - public string ClassPrefix { get; } - public string OneLiteral { get; } - public string ZeroLiteral { get; } - - public bool SupportsNumeric { get; } - public bool SupportsBitwise { get; } - public ISet UnsupportedMethods { get; } - } - - public string GenerateInPlaceStatement(string trueCondition, string falseCondition) - { - return $"inPlace ? {trueCondition} : {falseCondition}"; - } - - public string GenerateIfStatementHeader(TypeConfiguration type) - { - string keyword = (type == typeConfiguration[0]) ? "if" : "else if"; - return $"{keyword} (typeof(T) == typeof({type.TypeName}))"; - } - - // A way to discern implicit conversions. For ex: short has primitivitty 2. int has primitivitty 3. primitivitty(short) + primitivitty(int) > 2 * primitivitty(short) implying that a conversion has to take place - public Dictionary primitiveTypeToPrimitivityLevelMap = new Dictionary { - {"byte", 1}, - {"sbyte", 1}, - {"short", 2}, - {"ushort", 2}, - {"int", 3}, - {"uint", 3}, - {"long", 4}, - {"ulong", 4}, - {"float", 5}, - {"double", 6}, - {"decimal", 7} - }; - - public string GetCapitalizedPrimitiveTypes(string type) - { - string typeFirstCharUpper; - if (type.First() == 'u' || type == "sbyte") - { - typeFirstCharUpper = type[0].ToString().ToUpper() + type[1].ToString().ToUpper() + type.Substring(2); - } - else - { - typeFirstCharUpper = type[0].ToString().ToUpper() + type.Substring(1); - } - if (typeFirstCharUpper == "Bool") - { - return "Boolean"; - } - else if (typeFirstCharUpper == "Float") - { - return "Single"; - } - else if (typeFirstCharUpper == "Int") - { - return "Int32"; - } - else if (typeFirstCharUpper == "Short") - { - return "Int16"; - } - else if (typeFirstCharUpper == "Long") - { - return "Int64"; - } - else if (typeFirstCharUpper == "UInt") - { - return "UInt32"; - } - else if (typeFirstCharUpper == "UShort") - { - return "UInt16"; - } - else if (typeFirstCharUpper == "ULong") - { - return "UInt64"; - } - return typeFirstCharUpper; - } - - public bool IsMixedSignedAndUnsignedTypePair(string t1, string t2) - { - if (t1 == "byte" && t2 == "sbyte") - { - return true; - } - if (t2 == "byte" && t1 == "sbyte") - { - return true; - } - if (("u" + t1) == t2) - { - return true; - } - if (("u" + t2) == t1) - { - return true; - } - return false; - } - - // These are a subset of the implicit conversions allowed in C#. They are used to generate the return type for binary ops - // https://github.com/dotnet/csharplang/blob/master/spec/conversions.md#implicit-numeric-conversions - public Dictionary> primitiveTypeToImplicitConversions = new Dictionary> { - {"sbyte", new List {"int", "long", "float", "double", "decimal"}}, - {"byte", new List {"int", "uint", "long", "ulong", "float", "double", "decimal"}}, - {"short", new List {"int", "long", "float", "double", "decimal"}}, - {"ushort", new List {"int", "uint", "long", "ulong", "float", "double", "decimal"}}, - {"int", new List {"int", "long", "float", "double", "decimal"}}, - {"uint", new List {"uint", "long", "ulong", "float", "double", "decimal"}}, - {"long", new List {"long", "float", "double", "decimal"}}, - {"ulong", new List {"ulong", "float", "double", "decimal"}}, - {"float", new List {"float", "double"}}, - {"double", new List {"double"}}, - {"decimal", new List {"decimal"}}, - }; - - public TypeConfiguration[] typeConfiguration = new [] - { - new TypeConfiguration("bool", oneLiteral:"true", zeroLiteral:"false", supportsNumeric: false, unsupportedMethods: new[] {"LeftShift", "RightShift"}), - new TypeConfiguration("byte", unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("char", oneLiteral:"(char)1", zeroLiteral:"(char)0", unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("decimal", supportsBitwise: false, unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("double", oneLiteral:"1.0", supportsBitwise: false, unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("float", oneLiteral:"1.0f", supportsBitwise: false, unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("int", unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("long", unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("sbyte", classPrefix:"SByte", unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("short", unsupportedMethods: new[] {"All", "Any"}), - new TypeConfiguration("uint", classPrefix:"UInt", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}), - new TypeConfiguration("ulong", classPrefix:"ULong", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}), - new TypeConfiguration("ushort", classPrefix:"UShort", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}), - new TypeConfiguration("DateTime", supportsBitwise: false, supportsNumeric: false, unsupportedMethods: new[] {"And", "Or", "Xor"}) - }; - - public string GetBinaryShiftOperationReturnType(TypeConfiguration t1) - { - primitiveTypeToImplicitConversions.TryGetValue(t1.TypeName, out IReadOnlyList t1ImplicitConversions); - return t1ImplicitConversions.First() ?? string.Empty; - } - - public string GetBinaryOperationReturnType(string t1, string t2) - { - if (t1 == "long" && t2 == "ulong" || t1 == "ulong" && t2 == "long") - { - return string.Empty; - } - primitiveTypeToImplicitConversions.TryGetValue(t1, out IReadOnlyList t1ImplicitConversions); - primitiveTypeToImplicitConversions.TryGetValue(t2, out IReadOnlyList t2ImplicitConversions); - var intersection = t1ImplicitConversions.Intersect(t2ImplicitConversions); - string ret; - if (intersection.Count() == 0) - { - ret = string.Empty; - } - else - { - ret = intersection.First(); - } - return ret; - } - - // Returns an empty string for binary ops that are not valid: For ex: float + decimal is NOT allowed. - // Special case: long + ulong is NOT allowed. The other mixed signed and unsigned are valid - public string GetBinaryOperationReturnType(TypeConfiguration t1, TypeConfiguration t2) - { - string t1Type = t1.TypeName; - string t2Type = t2.TypeName; - return GetBinaryOperationReturnType(t1Type, t2Type); - } - - public enum MethodType - { - Unary, - UnaryInPlace, - BinaryScalar, - BinaryInt, - Binary, - Comparison, - ComparisonScalar, - Contraction, - ElementwiseComputation, - Reduction - } - - public MethodConfiguration[] computationMethodConfiguration = new [] - { - new MethodConfiguration("Abs", MethodType.ElementwiseComputation, "Math.Abs", isNumeric: true, methodComments: "Updates each numeric element with its absolute numeric value"), - new MethodConfiguration("All", MethodType.Reduction, "", isBitwise: true, methodComments: "Returns whether all the elements are True"), - new MethodConfiguration("Any", MethodType.Reduction, "", isBitwise: true, methodComments: "Returns whether any element is True"), - new MethodConfiguration("CumulativeMax", MethodType.ElementwiseComputation, "", isNumeric:true, methodComments: "Updates each element with its cumulative maximum"), - new MethodConfiguration("CumulativeMax", MethodType.ElementwiseComputation, "", isNumeric:true, supportsRowSubsets: true, methodComments: "Updates column values at rowIndices with its cumulative rowIndices maximum"), - new MethodConfiguration("CumulativeMin", MethodType.ElementwiseComputation, "", isNumeric:true, methodComments: "Updates each element with its cumulative minimum"), - new MethodConfiguration("CumulativeMin", MethodType.ElementwiseComputation, "", isNumeric:true, supportsRowSubsets: true, methodComments: "Updates column values at rowIndices with its cumulative rowIndices minimum"), - new MethodConfiguration("CumulativeProduct", MethodType.ElementwiseComputation, "", isNumeric:true, methodComments: "Updates each element with its cumulative product"), - new MethodConfiguration("CumulativeProduct", MethodType.ElementwiseComputation, "", isNumeric:true, supportsRowSubsets: true, methodComments: "Updates column values at rowIndices with its cumulative rowIndices product"), - new MethodConfiguration("CumulativeSum", MethodType.ElementwiseComputation, "", isNumeric:true, methodComments: "Updates each element with its cumulative sum"), - new MethodConfiguration("CumulativeSum", MethodType.ElementwiseComputation, "", isNumeric:true, supportsRowSubsets: true, methodComments: "Updates column values at rowIndices with its cumulative rowIndices sum"), - new MethodConfiguration("Max", MethodType.Reduction, "", isNumeric:true, hasReturnValue:true, methodComments: "Returns the maximum of the values in the column"), - new MethodConfiguration("Max", MethodType.Reduction, "", isNumeric:true, hasReturnValue:true, supportsRowSubsets: true, methodComments: "Returns the maximum of the values at rowIndices"), - new MethodConfiguration("Min", MethodType.Reduction, "", isNumeric:true, hasReturnValue:true, methodComments: "Returns the minimum of the values in the column"), - new MethodConfiguration("Min", MethodType.Reduction, "", isNumeric:true, hasReturnValue:true, supportsRowSubsets: true, methodComments: "Returns the minimum of the values at the rowIndices"), - new MethodConfiguration("Product", MethodType.Reduction, "*", isNumeric:true, hasReturnValue:true, methodComments: "Returns the product of the values in the column"), - new MethodConfiguration("Product", MethodType.Reduction, "*", isNumeric:true, hasReturnValue:true, supportsRowSubsets: true, methodComments: "Returns the product of the values at the rowIndices"), - new MethodConfiguration("Sum", MethodType.Reduction, "+", isNumeric:true, hasReturnValue:true, methodComments: "Returns the sum of the values in the column"), - new MethodConfiguration("Sum", MethodType.Reduction, "+", isNumeric:true, hasReturnValue:true, supportsRowSubsets: true, methodComments: "Returns the sum of the values at the rowIndices"), - new MethodConfiguration("Round", MethodType.ElementwiseComputation, "Math.Round", isNumeric:true, methodComments: "Calls Math.Round on each value in a column"), - }; - - public MethodConfiguration[] methodConfiguration = new [] - { - new MethodConfiguration("Add", MethodType.Binary, "+", isNumeric:true, methodComments: "Performs element-wise addition"), - new MethodConfiguration("Add", MethodType.BinaryScalar, "+", isNumeric:true, methodComments: "Performs an element-wise addition on each column"), - new MethodConfiguration("Subtract", MethodType.Binary, "-", isNumeric:true, methodComments: "Performs element-wise subtraction"), - new MethodConfiguration("Subtract", MethodType.BinaryScalar, "-", isNumeric:true, methodComments: "Performs an element-wise subtraction on each column"), - new MethodConfiguration("Multiply", MethodType.Binary, "*", isNumeric:true, methodComments: "Performs element-wise multiplication"), // element-wise product, not matrix product - new MethodConfiguration("Multiply", MethodType.BinaryScalar, "*", isNumeric:true, methodComments: "Performs an element-wise multiplication on each column"), - new MethodConfiguration("Divide", MethodType.Binary, "/", isNumeric:true, methodComments: "Performs element-wise division"), - new MethodConfiguration("Divide", MethodType.BinaryScalar, "/", isNumeric:true, methodComments: "Performs an element-wise division on each column"), - new MethodConfiguration("Modulo", MethodType.Binary, "%", isNumeric:true, methodComments: "Performs element-wise modulus"), - new MethodConfiguration("Modulo", MethodType.BinaryScalar, "%", isNumeric:true, methodComments: "Performs an element-wise modulus operation on each column"), - new MethodConfiguration("And", MethodType.Binary, "&", isBitwise: true, methodComments: "Performs element-wise boolean And"), - new MethodConfiguration("And", MethodType.BinaryScalar, "&", isBitwise: true, methodComments: "Performs an element-wise boolean And on each column"), - new MethodConfiguration("Or", MethodType.Binary, "|", isBitwise: true, methodComments: "Performs element-wise boolean Or"), - new MethodConfiguration("Or", MethodType.BinaryScalar, "|", isBitwise: true, methodComments: "Performs an element-wise boolean Or on each column"), - new MethodConfiguration("Xor", MethodType.Binary, "^", isBitwise: true, methodComments: "Performs element-wise boolean Xor"), - new MethodConfiguration("Xor", MethodType.BinaryScalar, "^", isBitwise: true, methodComments: "Performs an element-wise boolean Xor on each column"), - new MethodConfiguration("LeftShift", MethodType.BinaryInt, "<<", isBitwise: true, methodComments: "Performs an element-wise left shift on each column"), - new MethodConfiguration("RightShift", MethodType.BinaryInt, ">>", isBitwise: true, methodComments: "Performs an element-wise right shift on each column"), - - new MethodConfiguration("ElementwiseEquals", MethodType.Comparison, "==", methodComments: "Performs element-wise equals"), - new MethodConfiguration("ElementwiseEquals", MethodType.ComparisonScalar, "==", methodComments: "Performs an element-wise equals on each column"), - new MethodConfiguration("ElementwiseNotEquals", MethodType.Comparison, "!=", methodComments: "Performs element-wise not-equals"), - new MethodConfiguration("ElementwiseNotEquals", MethodType.ComparisonScalar, "!=", methodComments: "Performs an element-wise not-equals on each column"), - new MethodConfiguration("ElementwiseGreaterThanOrEqual", MethodType.Comparison, ">=", isNumeric:true, methodComments: "Performs element-wise greater than or equal"), - new MethodConfiguration("ElementwiseGreaterThanOrEqual", MethodType.ComparisonScalar, ">=", isNumeric:true, methodComments: "Performs an element-wise greater than or equal on each column"), - new MethodConfiguration("ElementwiseLessThanOrEqual", MethodType.Comparison, "<=", isNumeric:true, methodComments: "Performs element-wise less than or equal"), - new MethodConfiguration("ElementwiseLessThanOrEqual", MethodType.ComparisonScalar, "<=", isNumeric:true, methodComments: "Performs an element-wise less than or equal on each column"), - new MethodConfiguration("ElementwiseGreaterThan", MethodType.Comparison, ">", isNumeric:true, methodComments: "Performs element-wise greater than"), - new MethodConfiguration("ElementwiseGreaterThan", MethodType.ComparisonScalar, ">", isNumeric:true, methodComments: "Performs an element-wise greater than on each column"), - new MethodConfiguration("ElementwiseLessThan", MethodType.Comparison, "<", isNumeric:true, methodComments: "Performs element-wise less than"), - new MethodConfiguration("ElementwiseLessThan", MethodType.ComparisonScalar, "<", isNumeric:true, methodComments: "Performs an element-wise less than on each column"), - }; - - public class MethodConfiguration - { - public MethodConfiguration(string methodName, MethodType methodType, string op = null, bool isNumeric = false, bool isBitwise = false, bool hasReturnValue = false, bool supportsRowSubsets = false, string methodComments = null) - { - MethodName = methodName; - MethodType = methodType; - Operator = op; - IsNumeric = isNumeric; - IsBitwise = isBitwise; - HasReturnValue = hasReturnValue; - SupportsRowSubsets = supportsRowSubsets; - MethodComments = methodComments; - } - - public string ResultName => "result"; - - public string Op1Name - { - get - { - switch (MethodType) - { - case MethodType.Unary: - case MethodType.UnaryInPlace: - case MethodType.BinaryScalar: - case MethodType.BinaryInt: - case MethodType.ComparisonScalar: - case MethodType.ElementwiseComputation: - case MethodType.Reduction: - return "column"; - case MethodType.Binary: - case MethodType.Comparison: - case MethodType.Contraction: - return "left"; - default: - throw new ArgumentException(); - }; - } - } - - public string Op2Name - { - get - { - switch (MethodType) - { - case MethodType.BinaryScalar: - case MethodType.ComparisonScalar: - return "scalar"; - case MethodType.BinaryInt: - return "value"; - case MethodType.Binary: - case MethodType.Comparison: - case MethodType.Contraction: - return "right"; - case MethodType.Unary: - case MethodType.UnaryInPlace: - default: - throw new ArgumentException(); - }; - } - } - - public string MethodName { get; } - public MethodType MethodType { get; } - public string Operator { get; } - public string MethodComments { get; } - - public string GetColumnSpecificMethodComments() - { - var str = MethodComments; - return str.Replace("column", "value in the column"); - } - - public string GetReverseMethodComments() - { - var str = MethodComments; - return str.Replace(" an", " a reversed"); - } - - public string GetColumnSpecificBinaryMethodComments() - { - var str = MethodComments; - str = str.Replace("column", ""); - return str.Replace(" an", " "); - } - - public string GetColumnSpecificReverseMethodComments() - { - return GetColumnSpecificMethodComments().Replace(" an", " a reversed"); - } - - public string GetMethodSignature(string columnType, string genericType) - { - var arguments = GetMethodArguments(columnType, genericType); - return $"void {MethodName}({arguments})"; - } - - public string GetInvertedMethodSignatureForBinaryScalarsOps(string columnType, string genericType) - { - var arguments = GetInvertedMethodArguments(columnType, genericType); - return $"void {MethodName}({arguments})"; - } - - public string GetSingleArgumentMethodSignature(string columnType, string genericType) - { - var arguments = GetSingleParameterMethodArguments(columnType, genericType); - return $"PrimitiveColumnContainer {MethodName}({arguments})"; - } - - public string GetComputationOrReductionMethodSignature(string columnType, string genericType) - { - var arguments = GetMethodArguments(columnType, genericType); - switch (MethodType) - { - case MethodType.ElementwiseComputation: - return $"{columnType}<{genericType}> {MethodName}({arguments})"; - case MethodType.Reduction: - return $"{genericType} {MethodName}({arguments})"; - default: - throw new ArgumentException(); - } - } - - public string GetInvertedMethodArguments(string dataFrameType, string genericType) - { - switch (MethodType) - { - case MethodType.BinaryScalar: - return $"{genericType} {Op2Name}, {dataFrameType}<{genericType}> {Op1Name}"; - default: - throw new ArgumentException(); - } - } - - public string GetMethodArguments(string dataFrameType, string genericType) - { - switch (MethodType) - { - case MethodType.Unary: - case MethodType.UnaryInPlace: - return $"{dataFrameType}<{genericType}> {Op1Name}"; - case MethodType.BinaryScalar: - return $"{dataFrameType}<{genericType}> {Op1Name}, {genericType} {Op2Name}"; - case MethodType.ComparisonScalar: - return $"{dataFrameType}<{genericType}> {Op1Name}, {genericType} {Op2Name}, {dataFrameType} ret"; - case MethodType.BinaryInt: - return $"{dataFrameType}<{genericType}> {Op1Name}, int {Op2Name}"; - case MethodType.Binary: - return $"{dataFrameType}<{genericType}> {Op1Name}, {dataFrameType}<{genericType}> {Op2Name}"; - case MethodType.Comparison: - return $"{dataFrameType}<{genericType}> {Op1Name}, {dataFrameType}<{genericType}> {Op2Name}, {dataFrameType} ret"; - case MethodType.Contraction: - return $"{dataFrameType}<{genericType}> {Op1Name}, {dataFrameType}<{genericType}> {Op2Name}, int[] leftAxes, int[] rightAxes"; - case MethodType.ElementwiseComputation: - case MethodType.Reduction: - return $""; - default: - throw new ArgumentException(); - } - } - - public string GetSingleParameterMethodArguments(string dataFrameType, string genericType) - { - switch (MethodType) - { - case MethodType.Unary: - case MethodType.UnaryInPlace: - throw new ArgumentException(); - return $"{dataFrameType}<{genericType}> {Op1Name}"; - case MethodType.BinaryScalar: - return $"{genericType} {Op2Name}"; - case MethodType.ComparisonScalar: - return $"{genericType} {Op2Name}, {dataFrameType} ret"; - case MethodType.BinaryInt: - return $"int {Op2Name}"; - case MethodType.Binary: - return $"{dataFrameType}<{genericType}> {Op2Name}"; - case MethodType.Comparison: - return $"{dataFrameType}<{genericType}> {Op2Name}, {dataFrameType} ret"; - case MethodType.Contraction: - throw new ArgumentException(); - return $"{dataFrameType}<{genericType}> {Op1Name}, {dataFrameType}<{genericType}> {Op2Name}, int[] leftAxes, int[] rightAxes"; - default: - throw new ArgumentException(); - } - } - - public bool IsNumeric { get; } - public bool IsBitwise { get; } - public bool HasReturnValue { get; } - public bool SupportsRowSubsets { get; } - } -#> diff --git a/src/Microsoft.Data.Analysis/Converters.cs b/src/Microsoft.Data.Analysis/Converters.cs deleted file mode 100644 index a6900ea3f4..0000000000 --- a/src/Microsoft.Data.Analysis/Converters.cs +++ /dev/null @@ -1,948 +0,0 @@ - -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from Converters.tt. Do not modify directly - -using System; -using System.Collections.Generic; - -namespace Microsoft.Data.Analysis -{ - internal interface IByteConverter - { - byte GetByte(T value); - } - internal static class ByteConverter - { - public static IByteConverter Instance { get; } = ByteConverter.GetByteConverter(); - } - internal static class ByteConverter - { - public static IByteConverter GetByteConverter() - { - if (typeof(T) == typeof(byte)) - { - return (IByteConverter)new ByteByteConverter(); - } - if (typeof(T) == typeof(sbyte)) - { - return (IByteConverter)new SByteByteConverter(); - } - throw new NotSupportedException(); - } - } - internal class ByteByteConverter : IByteConverter - { - public byte GetByte(byte value) - { - return (byte)value; - } - } - internal class SByteByteConverter : IByteConverter - { - public byte GetByte(sbyte value) - { - return (byte)value; - } - } - internal interface ISByteConverter - { - sbyte GetSByte(T value); - } - internal static class SByteConverter - { - public static ISByteConverter Instance { get; } = SByteConverter.GetSByteConverter(); - } - internal static class SByteConverter - { - public static ISByteConverter GetSByteConverter() - { - if (typeof(T) == typeof(byte)) - { - return (ISByteConverter)new ByteSByteConverter(); - } - if (typeof(T) == typeof(sbyte)) - { - return (ISByteConverter)new SByteSByteConverter(); - } - throw new NotSupportedException(); - } - } - internal class ByteSByteConverter : ISByteConverter - { - public sbyte GetSByte(byte value) - { - return (sbyte)value; - } - } - internal class SByteSByteConverter : ISByteConverter - { - public sbyte GetSByte(sbyte value) - { - return (sbyte)value; - } - } - internal interface IInt16Converter - { - short GetInt16(T value); - } - internal static class Int16Converter - { - public static IInt16Converter Instance { get; } = Int16Converter.GetInt16Converter(); - } - internal static class Int16Converter - { - public static IInt16Converter GetInt16Converter() - { - if (typeof(T) == typeof(byte)) - { - return (IInt16Converter)new ByteInt16Converter(); - } - if (typeof(T) == typeof(sbyte)) - { - return (IInt16Converter)new SByteInt16Converter(); - } - if (typeof(T) == typeof(short)) - { - return (IInt16Converter)new Int16Int16Converter(); - } - if (typeof(T) == typeof(ushort)) - { - return (IInt16Converter)new UInt16Int16Converter(); - } - throw new NotSupportedException(); - } - } - internal class ByteInt16Converter : IInt16Converter - { - public short GetInt16(byte value) - { - return (short)value; - } - } - internal class SByteInt16Converter : IInt16Converter - { - public short GetInt16(sbyte value) - { - return (short)value; - } - } - internal class Int16Int16Converter : IInt16Converter - { - public short GetInt16(short value) - { - return (short)value; - } - } - internal class UInt16Int16Converter : IInt16Converter - { - public short GetInt16(ushort value) - { - return (short)value; - } - } - internal interface IUInt16Converter - { - ushort GetUInt16(T value); - } - internal static class UInt16Converter - { - public static IUInt16Converter Instance { get; } = UInt16Converter.GetUInt16Converter(); - } - internal static class UInt16Converter - { - public static IUInt16Converter GetUInt16Converter() - { - if (typeof(T) == typeof(byte)) - { - return (IUInt16Converter)new ByteUInt16Converter(); - } - if (typeof(T) == typeof(sbyte)) - { - return (IUInt16Converter)new SByteUInt16Converter(); - } - if (typeof(T) == typeof(short)) - { - return (IUInt16Converter)new Int16UInt16Converter(); - } - if (typeof(T) == typeof(ushort)) - { - return (IUInt16Converter)new UInt16UInt16Converter(); - } - throw new NotSupportedException(); - } - } - internal class ByteUInt16Converter : IUInt16Converter - { - public ushort GetUInt16(byte value) - { - return (ushort)value; - } - } - internal class SByteUInt16Converter : IUInt16Converter - { - public ushort GetUInt16(sbyte value) - { - return (ushort)value; - } - } - internal class Int16UInt16Converter : IUInt16Converter - { - public ushort GetUInt16(short value) - { - return (ushort)value; - } - } - internal class UInt16UInt16Converter : IUInt16Converter - { - public ushort GetUInt16(ushort value) - { - return (ushort)value; - } - } - internal interface IInt32Converter - { - int GetInt32(T value); - } - internal static class Int32Converter - { - public static IInt32Converter Instance { get; } = Int32Converter.GetInt32Converter(); - } - internal static class Int32Converter - { - public static IInt32Converter GetInt32Converter() - { - if (typeof(T) == typeof(byte)) - { - return (IInt32Converter)new ByteInt32Converter(); - } - if (typeof(T) == typeof(sbyte)) - { - return (IInt32Converter)new SByteInt32Converter(); - } - if (typeof(T) == typeof(short)) - { - return (IInt32Converter)new Int16Int32Converter(); - } - if (typeof(T) == typeof(ushort)) - { - return (IInt32Converter)new UInt16Int32Converter(); - } - if (typeof(T) == typeof(int)) - { - return (IInt32Converter)new Int32Int32Converter(); - } - if (typeof(T) == typeof(uint)) - { - return (IInt32Converter)new UInt32Int32Converter(); - } - throw new NotSupportedException(); - } - } - internal class ByteInt32Converter : IInt32Converter - { - public int GetInt32(byte value) - { - return (int)value; - } - } - internal class SByteInt32Converter : IInt32Converter - { - public int GetInt32(sbyte value) - { - return (int)value; - } - } - internal class Int16Int32Converter : IInt32Converter - { - public int GetInt32(short value) - { - return (int)value; - } - } - internal class UInt16Int32Converter : IInt32Converter - { - public int GetInt32(ushort value) - { - return (int)value; - } - } - internal class Int32Int32Converter : IInt32Converter - { - public int GetInt32(int value) - { - return (int)value; - } - } - internal class UInt32Int32Converter : IInt32Converter - { - public int GetInt32(uint value) - { - return (int)value; - } - } - internal interface IUInt32Converter - { - uint GetUInt32(T value); - } - internal static class UInt32Converter - { - public static IUInt32Converter Instance { get; } = UInt32Converter.GetUInt32Converter(); - } - internal static class UInt32Converter - { - public static IUInt32Converter GetUInt32Converter() - { - if (typeof(T) == typeof(byte)) - { - return (IUInt32Converter)new ByteUInt32Converter(); - } - if (typeof(T) == typeof(sbyte)) - { - return (IUInt32Converter)new SByteUInt32Converter(); - } - if (typeof(T) == typeof(short)) - { - return (IUInt32Converter)new Int16UInt32Converter(); - } - if (typeof(T) == typeof(ushort)) - { - return (IUInt32Converter)new UInt16UInt32Converter(); - } - if (typeof(T) == typeof(int)) - { - return (IUInt32Converter)new Int32UInt32Converter(); - } - if (typeof(T) == typeof(uint)) - { - return (IUInt32Converter)new UInt32UInt32Converter(); - } - throw new NotSupportedException(); - } - } - internal class ByteUInt32Converter : IUInt32Converter - { - public uint GetUInt32(byte value) - { - return (uint)value; - } - } - internal class SByteUInt32Converter : IUInt32Converter - { - public uint GetUInt32(sbyte value) - { - return (uint)value; - } - } - internal class Int16UInt32Converter : IUInt32Converter - { - public uint GetUInt32(short value) - { - return (uint)value; - } - } - internal class UInt16UInt32Converter : IUInt32Converter - { - public uint GetUInt32(ushort value) - { - return (uint)value; - } - } - internal class Int32UInt32Converter : IUInt32Converter - { - public uint GetUInt32(int value) - { - return (uint)value; - } - } - internal class UInt32UInt32Converter : IUInt32Converter - { - public uint GetUInt32(uint value) - { - return (uint)value; - } - } - internal interface IInt64Converter - { - long GetInt64(T value); - } - internal static class Int64Converter - { - public static IInt64Converter Instance { get; } = Int64Converter.GetInt64Converter(); - } - internal static class Int64Converter - { - public static IInt64Converter GetInt64Converter() - { - if (typeof(T) == typeof(byte)) - { - return (IInt64Converter)new ByteInt64Converter(); - } - if (typeof(T) == typeof(sbyte)) - { - return (IInt64Converter)new SByteInt64Converter(); - } - if (typeof(T) == typeof(short)) - { - return (IInt64Converter)new Int16Int64Converter(); - } - if (typeof(T) == typeof(ushort)) - { - return (IInt64Converter)new UInt16Int64Converter(); - } - if (typeof(T) == typeof(int)) - { - return (IInt64Converter)new Int32Int64Converter(); - } - if (typeof(T) == typeof(uint)) - { - return (IInt64Converter)new UInt32Int64Converter(); - } - if (typeof(T) == typeof(long)) - { - return (IInt64Converter)new Int64Int64Converter(); - } - if (typeof(T) == typeof(ulong)) - { - return (IInt64Converter)new UInt64Int64Converter(); - } - throw new NotSupportedException(); - } - } - internal class ByteInt64Converter : IInt64Converter - { - public long GetInt64(byte value) - { - return (long)value; - } - } - internal class SByteInt64Converter : IInt64Converter - { - public long GetInt64(sbyte value) - { - return (long)value; - } - } - internal class Int16Int64Converter : IInt64Converter - { - public long GetInt64(short value) - { - return (long)value; - } - } - internal class UInt16Int64Converter : IInt64Converter - { - public long GetInt64(ushort value) - { - return (long)value; - } - } - internal class Int32Int64Converter : IInt64Converter - { - public long GetInt64(int value) - { - return (long)value; - } - } - internal class UInt32Int64Converter : IInt64Converter - { - public long GetInt64(uint value) - { - return (long)value; - } - } - internal class Int64Int64Converter : IInt64Converter - { - public long GetInt64(long value) - { - return (long)value; - } - } - internal class UInt64Int64Converter : IInt64Converter - { - public long GetInt64(ulong value) - { - return (long)value; - } - } - internal interface IUInt64Converter - { - ulong GetUInt64(T value); - } - internal static class UInt64Converter - { - public static IUInt64Converter Instance { get; } = UInt64Converter.GetUInt64Converter(); - } - internal static class UInt64Converter - { - public static IUInt64Converter GetUInt64Converter() - { - if (typeof(T) == typeof(byte)) - { - return (IUInt64Converter)new ByteUInt64Converter(); - } - if (typeof(T) == typeof(sbyte)) - { - return (IUInt64Converter)new SByteUInt64Converter(); - } - if (typeof(T) == typeof(short)) - { - return (IUInt64Converter)new Int16UInt64Converter(); - } - if (typeof(T) == typeof(ushort)) - { - return (IUInt64Converter)new UInt16UInt64Converter(); - } - if (typeof(T) == typeof(int)) - { - return (IUInt64Converter)new Int32UInt64Converter(); - } - if (typeof(T) == typeof(uint)) - { - return (IUInt64Converter)new UInt32UInt64Converter(); - } - if (typeof(T) == typeof(long)) - { - return (IUInt64Converter)new Int64UInt64Converter(); - } - if (typeof(T) == typeof(ulong)) - { - return (IUInt64Converter)new UInt64UInt64Converter(); - } - throw new NotSupportedException(); - } - } - internal class ByteUInt64Converter : IUInt64Converter - { - public ulong GetUInt64(byte value) - { - return (ulong)value; - } - } - internal class SByteUInt64Converter : IUInt64Converter - { - public ulong GetUInt64(sbyte value) - { - return (ulong)value; - } - } - internal class Int16UInt64Converter : IUInt64Converter - { - public ulong GetUInt64(short value) - { - return (ulong)value; - } - } - internal class UInt16UInt64Converter : IUInt64Converter - { - public ulong GetUInt64(ushort value) - { - return (ulong)value; - } - } - internal class Int32UInt64Converter : IUInt64Converter - { - public ulong GetUInt64(int value) - { - return (ulong)value; - } - } - internal class UInt32UInt64Converter : IUInt64Converter - { - public ulong GetUInt64(uint value) - { - return (ulong)value; - } - } - internal class Int64UInt64Converter : IUInt64Converter - { - public ulong GetUInt64(long value) - { - return (ulong)value; - } - } - internal class UInt64UInt64Converter : IUInt64Converter - { - public ulong GetUInt64(ulong value) - { - return (ulong)value; - } - } - internal interface ISingleConverter - { - float GetSingle(T value); - } - internal static class SingleConverter - { - public static ISingleConverter Instance { get; } = SingleConverter.GetSingleConverter(); - } - internal static class SingleConverter - { - public static ISingleConverter GetSingleConverter() - { - if (typeof(T) == typeof(byte)) - { - return (ISingleConverter)new ByteSingleConverter(); - } - if (typeof(T) == typeof(sbyte)) - { - return (ISingleConverter)new SByteSingleConverter(); - } - if (typeof(T) == typeof(short)) - { - return (ISingleConverter)new Int16SingleConverter(); - } - if (typeof(T) == typeof(ushort)) - { - return (ISingleConverter)new UInt16SingleConverter(); - } - if (typeof(T) == typeof(int)) - { - return (ISingleConverter)new Int32SingleConverter(); - } - if (typeof(T) == typeof(uint)) - { - return (ISingleConverter)new UInt32SingleConverter(); - } - if (typeof(T) == typeof(long)) - { - return (ISingleConverter)new Int64SingleConverter(); - } - if (typeof(T) == typeof(ulong)) - { - return (ISingleConverter)new UInt64SingleConverter(); - } - if (typeof(T) == typeof(float)) - { - return (ISingleConverter)new SingleSingleConverter(); - } - throw new NotSupportedException(); - } - } - internal class ByteSingleConverter : ISingleConverter - { - public float GetSingle(byte value) - { - return (float)value; - } - } - internal class SByteSingleConverter : ISingleConverter - { - public float GetSingle(sbyte value) - { - return (float)value; - } - } - internal class Int16SingleConverter : ISingleConverter - { - public float GetSingle(short value) - { - return (float)value; - } - } - internal class UInt16SingleConverter : ISingleConverter - { - public float GetSingle(ushort value) - { - return (float)value; - } - } - internal class Int32SingleConverter : ISingleConverter - { - public float GetSingle(int value) - { - return (float)value; - } - } - internal class UInt32SingleConverter : ISingleConverter - { - public float GetSingle(uint value) - { - return (float)value; - } - } - internal class Int64SingleConverter : ISingleConverter - { - public float GetSingle(long value) - { - return (float)value; - } - } - internal class UInt64SingleConverter : ISingleConverter - { - public float GetSingle(ulong value) - { - return (float)value; - } - } - internal class SingleSingleConverter : ISingleConverter - { - public float GetSingle(float value) - { - return (float)value; - } - } - internal interface IDoubleConverter - { - double GetDouble(T value); - } - internal static class DoubleConverter - { - public static IDoubleConverter Instance { get; } = DoubleConverter.GetDoubleConverter(); - } - internal static class DoubleConverter - { - public static IDoubleConverter GetDoubleConverter() - { - if (typeof(T) == typeof(byte)) - { - return (IDoubleConverter)new ByteDoubleConverter(); - } - if (typeof(T) == typeof(sbyte)) - { - return (IDoubleConverter)new SByteDoubleConverter(); - } - if (typeof(T) == typeof(short)) - { - return (IDoubleConverter)new Int16DoubleConverter(); - } - if (typeof(T) == typeof(ushort)) - { - return (IDoubleConverter)new UInt16DoubleConverter(); - } - if (typeof(T) == typeof(int)) - { - return (IDoubleConverter)new Int32DoubleConverter(); - } - if (typeof(T) == typeof(uint)) - { - return (IDoubleConverter)new UInt32DoubleConverter(); - } - if (typeof(T) == typeof(long)) - { - return (IDoubleConverter)new Int64DoubleConverter(); - } - if (typeof(T) == typeof(ulong)) - { - return (IDoubleConverter)new UInt64DoubleConverter(); - } - if (typeof(T) == typeof(float)) - { - return (IDoubleConverter)new SingleDoubleConverter(); - } - if (typeof(T) == typeof(double)) - { - return (IDoubleConverter)new DoubleDoubleConverter(); - } - throw new NotSupportedException(); - } - } - internal class ByteDoubleConverter : IDoubleConverter - { - public double GetDouble(byte value) - { - return (double)value; - } - } - internal class SByteDoubleConverter : IDoubleConverter - { - public double GetDouble(sbyte value) - { - return (double)value; - } - } - internal class Int16DoubleConverter : IDoubleConverter - { - public double GetDouble(short value) - { - return (double)value; - } - } - internal class UInt16DoubleConverter : IDoubleConverter - { - public double GetDouble(ushort value) - { - return (double)value; - } - } - internal class Int32DoubleConverter : IDoubleConverter - { - public double GetDouble(int value) - { - return (double)value; - } - } - internal class UInt32DoubleConverter : IDoubleConverter - { - public double GetDouble(uint value) - { - return (double)value; - } - } - internal class Int64DoubleConverter : IDoubleConverter - { - public double GetDouble(long value) - { - return (double)value; - } - } - internal class UInt64DoubleConverter : IDoubleConverter - { - public double GetDouble(ulong value) - { - return (double)value; - } - } - internal class SingleDoubleConverter : IDoubleConverter - { - public double GetDouble(float value) - { - return (double)value; - } - } - internal class DoubleDoubleConverter : IDoubleConverter - { - public double GetDouble(double value) - { - return (double)value; - } - } - internal interface IDecimalConverter - { - decimal GetDecimal(T value); - } - internal static class DecimalConverter - { - public static IDecimalConverter Instance { get; } = DecimalConverter.GetDecimalConverter(); - } - internal static class DecimalConverter - { - public static IDecimalConverter GetDecimalConverter() - { - if (typeof(T) == typeof(byte)) - { - return (IDecimalConverter)new ByteDecimalConverter(); - } - if (typeof(T) == typeof(sbyte)) - { - return (IDecimalConverter)new SByteDecimalConverter(); - } - if (typeof(T) == typeof(short)) - { - return (IDecimalConverter)new Int16DecimalConverter(); - } - if (typeof(T) == typeof(ushort)) - { - return (IDecimalConverter)new UInt16DecimalConverter(); - } - if (typeof(T) == typeof(int)) - { - return (IDecimalConverter)new Int32DecimalConverter(); - } - if (typeof(T) == typeof(uint)) - { - return (IDecimalConverter)new UInt32DecimalConverter(); - } - if (typeof(T) == typeof(long)) - { - return (IDecimalConverter)new Int64DecimalConverter(); - } - if (typeof(T) == typeof(ulong)) - { - return (IDecimalConverter)new UInt64DecimalConverter(); - } - if (typeof(T) == typeof(float)) - { - return (IDecimalConverter)new SingleDecimalConverter(); - } - if (typeof(T) == typeof(double)) - { - return (IDecimalConverter)new DoubleDecimalConverter(); - } - if (typeof(T) == typeof(decimal)) - { - return (IDecimalConverter)new DecimalDecimalConverter(); - } - throw new NotSupportedException(); - } - } - internal class ByteDecimalConverter : IDecimalConverter - { - public decimal GetDecimal(byte value) - { - return (decimal)value; - } - } - internal class SByteDecimalConverter : IDecimalConverter - { - public decimal GetDecimal(sbyte value) - { - return (decimal)value; - } - } - internal class Int16DecimalConverter : IDecimalConverter - { - public decimal GetDecimal(short value) - { - return (decimal)value; - } - } - internal class UInt16DecimalConverter : IDecimalConverter - { - public decimal GetDecimal(ushort value) - { - return (decimal)value; - } - } - internal class Int32DecimalConverter : IDecimalConverter - { - public decimal GetDecimal(int value) - { - return (decimal)value; - } - } - internal class UInt32DecimalConverter : IDecimalConverter - { - public decimal GetDecimal(uint value) - { - return (decimal)value; - } - } - internal class Int64DecimalConverter : IDecimalConverter - { - public decimal GetDecimal(long value) - { - return (decimal)value; - } - } - internal class UInt64DecimalConverter : IDecimalConverter - { - public decimal GetDecimal(ulong value) - { - return (decimal)value; - } - } - internal class SingleDecimalConverter : IDecimalConverter - { - public decimal GetDecimal(float value) - { - return (decimal)value; - } - } - internal class DoubleDecimalConverter : IDecimalConverter - { - public decimal GetDecimal(double value) - { - return (decimal)value; - } - } - internal class DecimalDecimalConverter : IDecimalConverter - { - public decimal GetDecimal(decimal value) - { - return (decimal)value; - } - } -} diff --git a/src/Microsoft.Data.Analysis/Converters.tt b/src/Microsoft.Data.Analysis/Converters.tt deleted file mode 100644 index c21661f75e..0000000000 --- a/src/Microsoft.Data.Analysis/Converters.tt +++ /dev/null @@ -1,84 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude" #> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from Converters.tt. Do not modify directly - -using System; -using System.Collections.Generic; - -namespace Microsoft.Data.Analysis -{ -<# - foreach (var typeToLevel in primitiveTypeToPrimitivityLevelMap) - { - string type = typeToLevel.Key; - int level = typeToLevel.Value; - string typeFirstCharUpper = GetCapitalizedPrimitiveTypes(type); -#> - internal interface I<#=typeFirstCharUpper#>Converter - { - <#=type#> Get<#=typeFirstCharUpper#>(T value); - } - internal static class <#=typeFirstCharUpper#>Converter - { - public static I<#=typeFirstCharUpper#>Converter Instance { get; } = <#=typeFirstCharUpper#>Converter.Get<#=typeFirstCharUpper#>Converter(); - } - internal static class <#=typeFirstCharUpper#>Converter - { - public static I<#=typeFirstCharUpper#>Converter Get<#=typeFirstCharUpper#>Converter() - { -<# - foreach (var typeLoop in primitiveTypeToPrimitivityLevelMap) - { - int loopLevel = typeLoop.Value; - if (loopLevel > level) - { - continue; - } -#> - if (typeof(T) == typeof(<#=typeLoop.Key#>)) - { -<# - string capitalizedLoopPrimitive = GetCapitalizedPrimitiveTypes(typeLoop.Key); -#> - return (I<#=typeFirstCharUpper#>Converter)new <#=capitalizedLoopPrimitive#><#=typeFirstCharUpper#>Converter(); - } -<# - } -#> - throw new NotSupportedException(); - } - } -<# - // Generate the individual type converter classes - foreach (var typeLoop in primitiveTypeToPrimitivityLevelMap) - { - int loopLevel = typeLoop.Value; - if (loopLevel > level) - { - continue; - } - string capitalizedLoopPrimitive = GetCapitalizedPrimitiveTypes(typeLoop.Key); -#> - internal class <#=capitalizedLoopPrimitive#><#=typeFirstCharUpper#>Converter : I<#=typeFirstCharUpper#>Converter<<#=typeLoop.Key#>> - { - public <#=type#> Get<#=typeFirstCharUpper#>(<#=typeLoop.Key#> value) - { - return (<#=type#>)value; - } - } -<# - } -#> -<# - } -#> -} diff --git a/src/Microsoft.Data.Analysis/DataFrame.Arrow.cs b/src/Microsoft.Data.Analysis/DataFrame.Arrow.cs index dc5be46421..270cfff63b 100644 --- a/src/Microsoft.Data.Analysis/DataFrame.Arrow.cs +++ b/src/Microsoft.Data.Analysis/DataFrame.Arrow.cs @@ -22,43 +22,43 @@ private static void AppendDataFrameColumnFromArrowArray(Field field, IArrowArray BooleanArray arrowBooleanArray = (BooleanArray)arrowArray; ReadOnlyMemory valueBuffer = arrowBooleanArray.ValueBuffer.Memory; ReadOnlyMemory nullBitMapBuffer = arrowBooleanArray.NullBitmapBuffer.Memory; - dataFrameColumn = new BooleanDataFrameColumn(fieldName, valueBuffer, nullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); + dataFrameColumn = new PrimitiveDataFrameColumn(fieldName, valueBuffer, nullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); break; case ArrowTypeId.Double: PrimitiveArray arrowDoubleArray = (PrimitiveArray)arrowArray; ReadOnlyMemory doubleValueBuffer = arrowDoubleArray.ValueBuffer.Memory; ReadOnlyMemory doubleNullBitMapBuffer = arrowDoubleArray.NullBitmapBuffer.Memory; - dataFrameColumn = new DoubleDataFrameColumn(fieldName, doubleValueBuffer, doubleNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); + dataFrameColumn = new PrimitiveDataFrameColumn(fieldName, doubleValueBuffer, doubleNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); break; case ArrowTypeId.Float: PrimitiveArray arrowFloatArray = (PrimitiveArray)arrowArray; ReadOnlyMemory floatValueBuffer = arrowFloatArray.ValueBuffer.Memory; ReadOnlyMemory floatNullBitMapBuffer = arrowFloatArray.NullBitmapBuffer.Memory; - dataFrameColumn = new SingleDataFrameColumn(fieldName, floatValueBuffer, floatNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); + dataFrameColumn = new PrimitiveDataFrameColumn(fieldName, floatValueBuffer, floatNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); break; case ArrowTypeId.Int8: PrimitiveArray arrowsbyteArray = (PrimitiveArray)arrowArray; ReadOnlyMemory sbyteValueBuffer = arrowsbyteArray.ValueBuffer.Memory; ReadOnlyMemory sbyteNullBitMapBuffer = arrowsbyteArray.NullBitmapBuffer.Memory; - dataFrameColumn = new SByteDataFrameColumn(fieldName, sbyteValueBuffer, sbyteNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); + dataFrameColumn = new PrimitiveDataFrameColumn(fieldName, sbyteValueBuffer, sbyteNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); break; case ArrowTypeId.Int16: PrimitiveArray arrowshortArray = (PrimitiveArray)arrowArray; ReadOnlyMemory shortValueBuffer = arrowshortArray.ValueBuffer.Memory; ReadOnlyMemory shortNullBitMapBuffer = arrowshortArray.NullBitmapBuffer.Memory; - dataFrameColumn = new Int16DataFrameColumn(fieldName, shortValueBuffer, shortNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); + dataFrameColumn = new PrimitiveDataFrameColumn(fieldName, shortValueBuffer, shortNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); break; case ArrowTypeId.Int32: PrimitiveArray arrowIntArray = (PrimitiveArray)arrowArray; ReadOnlyMemory intValueBuffer = arrowIntArray.ValueBuffer.Memory; ReadOnlyMemory intNullBitMapBuffer = arrowIntArray.NullBitmapBuffer.Memory; - dataFrameColumn = new Int32DataFrameColumn(fieldName, intValueBuffer, intNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); + dataFrameColumn = new PrimitiveDataFrameColumn(fieldName, intValueBuffer, intNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); break; case ArrowTypeId.Int64: PrimitiveArray arrowLongArray = (PrimitiveArray)arrowArray; ReadOnlyMemory longValueBuffer = arrowLongArray.ValueBuffer.Memory; ReadOnlyMemory longNullBitMapBuffer = arrowLongArray.NullBitmapBuffer.Memory; - dataFrameColumn = new Int64DataFrameColumn(fieldName, longValueBuffer, longNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); + dataFrameColumn = new PrimitiveDataFrameColumn(fieldName, longValueBuffer, longNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); break; case ArrowTypeId.String: StringArray stringArray = (StringArray)arrowArray; @@ -71,25 +71,25 @@ private static void AppendDataFrameColumnFromArrowArray(Field field, IArrowArray PrimitiveArray arrowbyteArray = (PrimitiveArray)arrowArray; ReadOnlyMemory byteValueBuffer = arrowbyteArray.ValueBuffer.Memory; ReadOnlyMemory byteNullBitMapBuffer = arrowbyteArray.NullBitmapBuffer.Memory; - dataFrameColumn = new ByteDataFrameColumn(fieldName, byteValueBuffer, byteNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); + dataFrameColumn = new PrimitiveDataFrameColumn(fieldName, byteValueBuffer, byteNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); break; case ArrowTypeId.UInt16: PrimitiveArray arrowUshortArray = (PrimitiveArray)arrowArray; ReadOnlyMemory ushortValueBuffer = arrowUshortArray.ValueBuffer.Memory; ReadOnlyMemory ushortNullBitMapBuffer = arrowUshortArray.NullBitmapBuffer.Memory; - dataFrameColumn = new UInt16DataFrameColumn(fieldName, ushortValueBuffer, ushortNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); + dataFrameColumn = new PrimitiveDataFrameColumn(fieldName, ushortValueBuffer, ushortNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); break; case ArrowTypeId.UInt32: PrimitiveArray arrowUintArray = (PrimitiveArray)arrowArray; ReadOnlyMemory uintValueBuffer = arrowUintArray.ValueBuffer.Memory; ReadOnlyMemory uintNullBitMapBuffer = arrowUintArray.NullBitmapBuffer.Memory; - dataFrameColumn = new UInt32DataFrameColumn(fieldName, uintValueBuffer, uintNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); + dataFrameColumn = new PrimitiveDataFrameColumn(fieldName, uintValueBuffer, uintNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); break; case ArrowTypeId.UInt64: PrimitiveArray arrowUlongArray = (PrimitiveArray)arrowArray; ReadOnlyMemory ulongValueBuffer = arrowUlongArray.ValueBuffer.Memory; ReadOnlyMemory ulongNullBitMapBuffer = arrowUlongArray.NullBitmapBuffer.Memory; - dataFrameColumn = new UInt64DataFrameColumn(fieldName, ulongValueBuffer, ulongNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); + dataFrameColumn = new PrimitiveDataFrameColumn(fieldName, ulongValueBuffer, ulongNullBitMapBuffer, arrowArray.Length, arrowArray.NullCount); break; case ArrowTypeId.Struct: StructArray structArray = (StructArray)arrowArray; @@ -101,10 +101,18 @@ private static void AppendDataFrameColumnFromArrowArray(Field field, IArrowArray AppendDataFrameColumnFromArrowArray(fieldsEnumerator.Current, structArrayEnumerator.Current, ret, field.Name + "_"); } break; - case ArrowTypeId.Decimal: + case ArrowTypeId.Date64: + Date64Array arrowDate64Array = (Date64Array)arrowArray; + dataFrameColumn = new PrimitiveDataFrameColumn(fieldName, arrowDate64Array.Data.Length); + for (int i = 0; i < arrowDate64Array.Data.Length; i++) + { + dataFrameColumn[i] = arrowDate64Array.GetDateTime(i); + } + break; + case ArrowTypeId.Decimal128: + case ArrowTypeId.Decimal256: case ArrowTypeId.Binary: case ArrowTypeId.Date32: - case ArrowTypeId.Date64: case ArrowTypeId.Dictionary: case ArrowTypeId.FixedSizedBinary: case ArrowTypeId.HalfFloat: @@ -114,6 +122,7 @@ private static void AppendDataFrameColumnFromArrowArray(Field field, IArrowArray case ArrowTypeId.Null: case ArrowTypeId.Time32: case ArrowTypeId.Time64: + case ArrowTypeId.Timestamp: default: throw new NotImplementedException($"{fieldType.Name}"); } @@ -145,7 +154,7 @@ public static DataFrame FromArrowRecordBatch(RecordBatch recordBatch) } /// - /// Returns an without copying data + /// Returns an mostly without copying data /// public IEnumerable ToArrowRecordBatches() { diff --git a/src/Microsoft.Data.Analysis/DataFrame.BinaryOperations.tt b/src/Microsoft.Data.Analysis/DataFrame.BinaryOperations.tt deleted file mode 100644 index cbd854109e..0000000000 --- a/src/Microsoft.Data.Analysis/DataFrame.BinaryOperations.tt +++ /dev/null @@ -1,136 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude" #> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from DataFrameBinaryOperations.tt. Do not modify directly - -using System; -using System.Collections.Generic; - -namespace Microsoft.Data.Analysis -{ - public partial class DataFrame - { -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.BinaryScalar) { #> -<# if (method.IsBitwise == true) { #> - /// - /// <#=method.MethodComments#> - /// - public DataFrame <#=method.MethodName#>(bool value, bool inPlace = false) -<# } else { #> - /// - /// <#=method.MethodComments#> - /// - public DataFrame <#=method.MethodName#>(T value, bool inPlace = false) - where T : unmanaged -<# } #> -<# } #> -<# if (method.MethodType == MethodType.ComparisonScalar) { #> - /// - /// <#=method.MethodComments#> - /// - public DataFrame <#=method.MethodName#>(T value) - where T : unmanaged -<# } #> -<# if (method.MethodType == MethodType.Binary) {#> -<# if (method.IsBitwise == true) { #> - public DataFrame <#=method.MethodName#>(IReadOnlyList values, bool inPlace = false) -<# } else { #> - public DataFrame <#=method.MethodName#>(IReadOnlyList values, bool inPlace = false) - where T : unmanaged -<# } #> -<# } #> -<# if (method.MethodType == MethodType.Comparison) {#> - public DataFrame <#=method.MethodName#>(IReadOnlyList values) - where T : unmanaged -<# } #> -<# if (method.MethodType == MethodType.BinaryInt ) {#> - /// - /// <#=method.MethodComments#> - /// - public DataFrame <#=method.MethodName#>(int value, bool inPlace = false) -<# } #> - { -<# if (method.MethodType == MethodType.BinaryScalar || method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.BinaryInt) {#> -<# } else { #> - if (values.Count != Columns.Count) - { - throw new ArgumentException(Strings.MismatchedColumnLengths, nameof(values)); - } -<# } #> -<# if (method.MethodType == MethodType.BinaryScalar || method.MethodType == MethodType.Binary || method.MethodType == MethodType.BinaryInt) {#> - DataFrame retDataFrame = inPlace ? this : new DataFrame(); -<# } else { #> - DataFrame retDataFrame = new DataFrame(); -<# } #> - -<# if (method.MethodType == MethodType.BinaryScalar || method.MethodType == MethodType.Binary || method.MethodType == MethodType.BinaryInt) {#> - for (int i = 0; i < Columns.Count; i++) - { - DataFrameColumn baseColumn = _columnCollection[i]; -<# } else { #> - for (int i = 0; i < Columns.Count; i++) - { - DataFrameColumn baseColumn = _columnCollection[i]; -<# } #> -<# if (method.MethodType == MethodType.BinaryScalar || method.MethodType == MethodType.BinaryInt) {#> - DataFrameColumn newColumn = baseColumn.<#=method.MethodName#>(value, inPlace); -<# } else if (method.MethodType == MethodType.Binary) { #> - DataFrameColumn newColumn = baseColumn.<#=method.MethodName#>(values[i], inPlace); -<# } else if (method.MethodType == MethodType.ComparisonScalar) { #> - DataFrameColumn newColumn = baseColumn.<#=method.MethodName#>(value); -<# } else { #> - DataFrameColumn newColumn = baseColumn.<#=method.MethodName#>(values[i]); -<# } #> -<# if (method.MethodType == MethodType.BinaryScalar || method.MethodType == MethodType.Binary || method.MethodType == MethodType.BinaryInt) {#> - if (inPlace) - retDataFrame.Columns[i] = newColumn; - else - retDataFrame.Columns.Insert(i, newColumn); -<# } else { #> - retDataFrame.Columns.Insert(i, newColumn); -<# } #> - } - return retDataFrame; - } -<# } #> - -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.BinaryScalar) { #> -<# if (method.IsBitwise == true) { #> - /// - /// <#=method.GetReverseMethodComments()#> - /// - public DataFrame Reverse<#=method.MethodName#>(bool value, bool inPlace = false) -<# } else { #> - /// - /// <#=method.GetReverseMethodComments()#> - /// - public DataFrame Reverse<#=method.MethodName#>(T value, bool inPlace = false) - where T : unmanaged -<# } #> - { - DataFrame retDataFrame = inPlace ? this : new DataFrame(); - for (int i = 0; i < Columns.Count; i++) - { - DataFrameColumn baseColumn = _columnCollection[i]; - DataFrameColumn newColumn = baseColumn.Reverse<#=method.MethodName#>(value, inPlace); - if (inPlace) - retDataFrame.Columns[i] = newColumn; - else - retDataFrame.Columns.Insert(i, newColumn); - } - return retDataFrame; - } -<# } #> -<# } #> - } -} diff --git a/src/Microsoft.Data.Analysis/DataFrame.BinaryOperators.tt b/src/Microsoft.Data.Analysis/DataFrame.BinaryOperators.tt deleted file mode 100644 index f2c525b8f7..0000000000 --- a/src/Microsoft.Data.Analysis/DataFrame.BinaryOperators.tt +++ /dev/null @@ -1,52 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude" #> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from DataFrameBinaryOperators.tt. Do not modify directly - -using System; -using System.Collections.Generic; - -namespace Microsoft.Data.Analysis -{ - public partial class DataFrame - { -#pragma warning disable 1591 -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.BinaryScalar) { #> -<# if (method.IsBitwise == true) { #> -<# // There seem to be very few use cases for an API such as df.And/Or/Xor(true). #> -<# continue; #> -<# } else { #> -<# foreach (TypeConfiguration type in typeConfiguration) { #> -<# if (method.IsNumeric != type.SupportsNumeric) continue; #> -<# if (method.IsNumeric && type.TypeName == "char") continue; #> - public static DataFrame operator <#=method.Operator#>(DataFrame df, <#=type.TypeName#> value) - { - return df.<#=method.MethodName#>(value); - } - - public static DataFrame operator <#=method.Operator#>(<#=type.TypeName#> value, DataFrame df) - { - return df.Reverse<#=method.MethodName#>(value); - } - -<# } #> -<# } #> -<# } else if (method.MethodType == MethodType.BinaryInt) {#> - public static DataFrame operator <#=method.Operator#>(DataFrame df, int value) - { - return df.<#=method.MethodName#>(value); - } - -<# } #> -<# } #> - } -} diff --git a/src/Microsoft.Data.Analysis/DataFrame.IO.cs b/src/Microsoft.Data.Analysis/DataFrame.IO.cs index e525624998..adde1103b4 100644 --- a/src/Microsoft.Data.Analysis/DataFrame.IO.cs +++ b/src/Microsoft.Data.Analysis/DataFrame.IO.cs @@ -280,15 +280,15 @@ private static DataFrameColumn CreateColumn(Type kind, string columnName) DataFrameColumn ret; if (kind == typeof(bool)) { - ret = new BooleanDataFrameColumn(columnName); + ret = new PrimitiveDataFrameColumn(columnName); } else if (kind == typeof(int)) { - ret = new Int32DataFrameColumn(columnName); + ret = new PrimitiveDataFrameColumn(columnName); } else if (kind == typeof(float)) { - ret = new SingleDataFrameColumn(columnName); + ret = new PrimitiveDataFrameColumn(columnName); } else if (kind == typeof(string)) { @@ -296,43 +296,43 @@ private static DataFrameColumn CreateColumn(Type kind, string columnName) } else if (kind == typeof(long)) { - ret = new Int64DataFrameColumn(columnName); + ret = new PrimitiveDataFrameColumn(columnName); } else if (kind == typeof(decimal)) { - ret = new DecimalDataFrameColumn(columnName); + ret = new PrimitiveDataFrameColumn(columnName); } else if (kind == typeof(byte)) { - ret = new ByteDataFrameColumn(columnName); + ret = new PrimitiveDataFrameColumn(columnName); } else if (kind == typeof(char)) { - ret = new CharDataFrameColumn(columnName); + ret = new PrimitiveDataFrameColumn(columnName); } else if (kind == typeof(double)) { - ret = new DoubleDataFrameColumn(columnName); + ret = new PrimitiveDataFrameColumn(columnName); } else if (kind == typeof(sbyte)) { - ret = new SByteDataFrameColumn(columnName); + ret = new PrimitiveDataFrameColumn(columnName); } else if (kind == typeof(short)) { - ret = new Int16DataFrameColumn(columnName); + ret = new PrimitiveDataFrameColumn(columnName); } else if (kind == typeof(uint)) { - ret = new UInt32DataFrameColumn(columnName); + ret = new PrimitiveDataFrameColumn(columnName); } else if (kind == typeof(ulong)) { - ret = new UInt64DataFrameColumn(columnName); + ret = new PrimitiveDataFrameColumn(columnName); } else if (kind == typeof(ushort)) { - ret = new UInt16DataFrameColumn(columnName); + ret = new PrimitiveDataFrameColumn(columnName); } else if (kind == typeof(DateTime)) { diff --git a/src/Microsoft.Data.Analysis/DataFrame.Join.cs b/src/Microsoft.Data.Analysis/DataFrame.Join.cs index 79291a691e..8e4029ffd3 100644 --- a/src/Microsoft.Data.Analysis/DataFrame.Join.cs +++ b/src/Microsoft.Data.Analysis/DataFrame.Join.cs @@ -30,7 +30,7 @@ private void SetSuffixForDuplicatedColumnNames(DataFrame dataFrame, DataFrameCol { // Pre-existing column. Change name DataFrameColumn existingColumn = dataFrame.Columns[index]; - dataFrame._columnCollection.SetColumnName(existingColumn, existingColumn.Name + leftSuffix); + existingColumn.SetName(existingColumn.Name + leftSuffix); column.SetName(column.Name + rightSuffix); index = dataFrame._columnCollection.IndexOf(column.Name); } @@ -221,7 +221,7 @@ private static Dictionary> GetOccurences(DataFrame retai retainedIndicesReverseMapping = newRetainedIndicesReverseMapping; - var indices = new Int64DataFrameColumn("Indices", shrinkedRetainedIndices); + var indices = new PrimitiveDataFrameColumn("Indices", shrinkedRetainedIndices); shrinkedRetainedColumn = shrinkedRetainedColumn.Clone(indices); } @@ -277,8 +277,8 @@ private static HashSet PerformMerging(DataFrame retainedDataFrame, string[ out PrimitiveDataFrameColumn retainedRowIndices, out PrimitiveDataFrameColumn supplementaryRowIndices, bool isInner, bool calculateIntersection) { - retainedRowIndices = new Int64DataFrameColumn("RetainedIndices"); - supplementaryRowIndices = new Int64DataFrameColumn("SupplementaryIndices"); + retainedRowIndices = new PrimitiveDataFrameColumn("RetainedIndices"); + supplementaryRowIndices = new PrimitiveDataFrameColumn("SupplementaryIndices"); HashSet intersection = calculateIntersection ? new HashSet() : null; diff --git a/src/Microsoft.Data.Analysis/DataFrame.cs b/src/Microsoft.Data.Analysis/DataFrame.cs index 6c24476549..25a8cbbfbc 100644 --- a/src/Microsoft.Data.Analysis/DataFrame.cs +++ b/src/Microsoft.Data.Analysis/DataFrame.cs @@ -301,7 +301,7 @@ public DataFrame AddPrefix(string prefix, bool inPlace = false) for (int i = 0; i < df.Columns.Count; i++) { DataFrameColumn column = df.Columns[i]; - df._columnCollection.SetColumnName(column, prefix + column.Name); + column.SetName(prefix + column.Name); df.OnColumnsChanged(); } return df; @@ -316,7 +316,7 @@ public DataFrame AddSuffix(string suffix, bool inPlace = false) for (int i = 0; i < df.Columns.Count; i++) { DataFrameColumn column = df.Columns[i]; - df._columnCollection.SetColumnName(column, column.Name + suffix); + column.SetName(column.Name + suffix); df.OnColumnsChanged(); } return df; @@ -643,7 +643,7 @@ private void OnColumnsChanged() private DataFrame Sort(string columnName, bool isAscending) { DataFrameColumn column = Columns[columnName]; - PrimitiveDataFrameColumn sortIndices = column.GetAscendingSortIndices(out Int64DataFrameColumn nullIndices); + PrimitiveDataFrameColumn sortIndices = column.GetAscendingSortIndices(out PrimitiveDataFrameColumn nullIndices); for (long i = 0; i < nullIndices.Length; i++) { sortIndices.Append(nullIndices[i]); diff --git a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.cs b/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.cs index 8ecd052486..1c340575db 100644 --- a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.cs +++ b/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.cs @@ -316,5 +316,20 @@ public virtual PrimitiveDataFrameColumn ElementwiseLessThan(T value) throw new NotImplementedException(); } + /// + /// Performs an element-wise equal to Null on each value in the column + /// + public virtual PrimitiveDataFrameColumn ElementwiseIsNull() + { + throw new NotImplementedException(); + } + + /// + /// Performs an element-wise not equal to Null on each value in the column + /// + public virtual PrimitiveDataFrameColumn ElementwiseIsNotNull() + { + throw new NotImplementedException(); + } } } diff --git a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.tt b/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.tt deleted file mode 100644 index d2e289195c..0000000000 --- a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperations.tt +++ /dev/null @@ -1,82 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude"#> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from DataFrameColumn.BinaryOperations.tt. Do not modify directly - -using System; -using System.Collections.Generic; - -namespace Microsoft.Data.Analysis -{ - public abstract partial class DataFrameColumn - { -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.BinaryScalar) { #> -<# if (method.IsBitwise == true) { #> - /// - /// <#=method.GetColumnSpecificMethodComments()#> - /// - public virtual PrimitiveDataFrameColumn <#=method.MethodName#>(bool value, bool inPlace = false) -<# } else { #> - /// - /// <#=method.GetColumnSpecificMethodComments()#> - /// - public virtual DataFrameColumn <#=method.MethodName#>(T value, bool inPlace = false) -<# } #> -<# } #> -<# if (method.MethodType == MethodType.ComparisonScalar) { #> - /// - /// <#=method.GetColumnSpecificMethodComments()#> - /// - public virtual PrimitiveDataFrameColumn <#=method.MethodName#>(T value) -<# } #> -<# if (method.MethodType == MethodType.Binary) {#> - /// - /// <#=method.MethodComments#> - /// - public virtual DataFrameColumn <#=method.MethodName#>(DataFrameColumn column, bool inPlace = false) -<# } #> -<# if (method.MethodType == MethodType.Comparison) {#> - /// - /// <#=method.MethodComments#> - /// - public virtual PrimitiveDataFrameColumn <#=method.MethodName#>(DataFrameColumn column) -<# } #> -<# if (method.MethodType == MethodType.BinaryInt ) {#> - /// - /// <#=method.GetColumnSpecificMethodComments()#> - /// - public virtual DataFrameColumn <#=method.MethodName#>(int value, bool inPlace = false) -<# } #> - { - throw new NotImplementedException(); - } - -<# if (method.MethodType == MethodType.BinaryScalar) { #> -<# if (method.IsBitwise == true) { #> - /// - /// <#=method.GetColumnSpecificReverseMethodComments()#> - /// - public virtual PrimitiveDataFrameColumn Reverse<#=method.MethodName#>(bool value, bool inPlace = false) -<# } else { #> - /// - /// <#=method.GetColumnSpecificReverseMethodComments()#> - /// - public virtual DataFrameColumn Reverse<#=method.MethodName#>(T value, bool inPlace = false) -<# } #> - { - throw new NotImplementedException(); - } - -<# } #> -<# } #> - } -} diff --git a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperators.tt b/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperators.tt deleted file mode 100644 index e55c8249df..0000000000 --- a/src/Microsoft.Data.Analysis/DataFrameColumn.BinaryOperators.tt +++ /dev/null @@ -1,67 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude" #> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from DataFrameColumn.BinaryOperators.tt. Do not modify directly - -using System; -using System.Collections.Generic; - -namespace Microsoft.Data.Analysis -{ - public abstract partial class DataFrameColumn - { -#pragma warning disable 1591 -<# foreach (MethodConfiguration method in methodConfiguration) { #> -<# if (method.MethodType == MethodType.BinaryScalar) { #> -<# if (method.IsBitwise == true) { #> - public static DataFrameColumn operator <#=method.Operator#>(DataFrameColumn column, bool value) - { - return column.<#=method.MethodName#>(value); - } - - public static DataFrameColumn operator <#=method.Operator#>(bool value, DataFrameColumn column) - { - return column.Reverse<#=method.MethodName#>(value); - } - -<# } else { #> -<# foreach (TypeConfiguration type in typeConfiguration) { #> -<# if (method.IsNumeric != type.SupportsNumeric) continue; #> -<# if (method.IsNumeric && type.TypeName == "char") continue; #> - public static DataFrameColumn operator <#=method.Operator#>(DataFrameColumn column, <#=type.TypeName#> value) - { - return column.<#=method.MethodName#>(value); - } - - public static DataFrameColumn operator <#=method.Operator#>(<#=type.TypeName#> value, DataFrameColumn column) - { - return column.Reverse<#=method.MethodName#>(value); - } - -<# } #> - -<# } #> -<# } else if (method.MethodType == MethodType.BinaryInt) {#> - public static DataFrameColumn operator <#=method.Operator#>(DataFrameColumn column, int value) - { - return column.<#=method.MethodName#>(value); - } - -<# } else if (method.MethodType == MethodType.Binary) { #> - public static DataFrameColumn operator <#=method.Operator#>(DataFrameColumn left, DataFrameColumn right) - { - return left.<#=method.MethodName#>(right); - } - -<# } #> -<# } #> - } -} diff --git a/src/Microsoft.Data.Analysis/DataFrameColumn.Computations.tt b/src/Microsoft.Data.Analysis/DataFrameColumn.Computations.tt deleted file mode 100644 index ebe4785ae7..0000000000 --- a/src/Microsoft.Data.Analysis/DataFrameColumn.Computations.tt +++ /dev/null @@ -1,44 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> -<#@ include file="ColumnArithmeticTemplate.ttinclude"#> -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// Generated from DataFrameColumn.Computations.tt. Do not modify directly - -using System; -using System.Collections.Generic; - -namespace Microsoft.Data.Analysis -{ - public abstract partial class DataFrameColumn - { -<# foreach (MethodConfiguration compMethod in computationMethodConfiguration) { #> - /// - /// <#=compMethod.MethodComments#> - /// -<# if (compMethod.MethodType == MethodType.ElementwiseComputation && compMethod.HasReturnValue == false && compMethod.SupportsRowSubsets == true) {#> - public virtual DataFrameColumn <#=compMethod.MethodName#>(IEnumerable rowIndices, bool inPlace = false) -<# } else if (compMethod.MethodType == MethodType.ElementwiseComputation && compMethod.HasReturnValue == false) {#> - public virtual DataFrameColumn <#=compMethod.MethodName#>(bool inPlace = false) -<# } else if (compMethod.MethodType == MethodType.ElementwiseComputation && compMethod.HasReturnValue == true) {#> - public virtual object <#=compMethod.MethodName#>() -<# } else if (compMethod.MethodType == MethodType.Reduction && compMethod.IsNumeric == true && compMethod.SupportsRowSubsets == true) { #> - public virtual object <#=compMethod.MethodName#>(IEnumerable rowIndices) -<# } else if (compMethod.MethodType == MethodType.Reduction && compMethod.IsNumeric == true) { #> - public virtual object <#=compMethod.MethodName#>() -<# } else { #> - public virtual bool <#=compMethod.MethodName#>() -<# } #> - { - throw new NotImplementedException(); - } - -<# } #> - } -} diff --git a/src/Microsoft.Data.Analysis/DataFrameColumn.cs b/src/Microsoft.Data.Analysis/DataFrameColumn.cs index 636d7a8db1..1b55b92d8f 100644 --- a/src/Microsoft.Data.Analysis/DataFrameColumn.cs +++ b/src/Microsoft.Data.Analysis/DataFrameColumn.cs @@ -84,6 +84,26 @@ protected set } } + // List of ColumnCollections that owns the column + // Current API allows column to be added into multiple dataframes, that's why the list is needed + private readonly List _ownerColumnCollections = new(); + + internal void AddOwner(DataFrameColumnCollection columCollection) + { + if (!_ownerColumnCollections.Contains(columCollection)) + { + _ownerColumnCollections.Add(columCollection); + } + } + + internal void RemoveOwner(DataFrameColumnCollection columCollection) + { + if (_ownerColumnCollections.Contains(columCollection)) + { + _ownerColumnCollections.Remove(columCollection); + } + } + /// /// The number of values in this column. /// @@ -95,24 +115,30 @@ public abstract long NullCount private string _name; /// - /// The name of this column. + /// The column name. /// public string Name => _name; /// - /// Updates the name of this column. + /// Updates the column name. /// /// The new name. - /// If passed in, update the column name in - public void SetName(string newName, DataFrame dataFrame = null) + public void SetName(string newName) { - if (!(dataFrame is null)) - { - dataFrame.Columns.SetColumnName(this, newName); - } + foreach (var owner in _ownerColumnCollections) + owner.UpdateColumnNameMetadata(this, newName); + _name = newName; } + /// + /// Updates the name of this column. + /// + /// The new name. + /// Ignored (for backward compatibility) + [Obsolete] + public void SetName(string newName, DataFrame dataFrame) => SetName(newName); + /// /// The type of data this column holds. /// @@ -199,7 +225,7 @@ public object this[long rowIndex] /// public virtual DataFrameColumn Sort(bool ascending = true) { - PrimitiveDataFrameColumn sortIndices = GetAscendingSortIndices(out Int64DataFrameColumn _); + PrimitiveDataFrameColumn sortIndices = GetAscendingSortIndices(out PrimitiveDataFrameColumn _); return Clone(sortIndices, !ascending, NullCount); } @@ -378,7 +404,7 @@ public virtual StringDataFrameColumn Info() /// Returns the indices of non-null values that, when applied, result in this column being sorted in ascending order. Also returns the indices of null values in . /// /// Indices of values that are . - internal virtual PrimitiveDataFrameColumn GetAscendingSortIndices(out Int64DataFrameColumn nullIndices) => throw new NotImplementedException(); + internal virtual PrimitiveDataFrameColumn GetAscendingSortIndices(out PrimitiveDataFrameColumn nullIndices) => throw new NotImplementedException(); internal delegate long GetBufferSortIndex(int bufferIndex, int sortIndex); internal delegate ValueTuple GetValueAndBufferSortIndexAtBuffer(int bufferIndex, int valueIndex); diff --git a/src/Microsoft.Data.Analysis/DataFrameColumnCollection.cs b/src/Microsoft.Data.Analysis/DataFrameColumnCollection.cs index bad2a42f95..13c363660c 100644 --- a/src/Microsoft.Data.Analysis/DataFrameColumnCollection.cs +++ b/src/Microsoft.Data.Analysis/DataFrameColumnCollection.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -38,11 +38,23 @@ internal IReadOnlyList GetColumnNames() return ret; } + public void RenameColumn(string currentName, string newName) + { + var column = this[currentName]; + column.SetName(newName); + } + + [Obsolete] public void SetColumnName(DataFrameColumn column, string newName) + { + column.SetName(newName); + } + + //Updates column's metadata (is used as a callback from Column class) + internal void UpdateColumnNameMetadata(DataFrameColumn column, string newName) { string currentName = column.Name; int currentIndex = _columnNameToIndexDictionary[currentName]; - column.SetName(newName); _columnNameToIndexDictionary.Remove(currentName); _columnNameToIndexDictionary.Add(newName, currentIndex); ColumnsChanged?.Invoke(); @@ -66,7 +78,7 @@ protected override void InsertItem(int columnIndex, DataFrameColumn column) } else if (column.Length != RowCount) { - //check all columns in the dataframe have the same length (amount of rows) + //check all columns in the dataframe have the same lenght (amount of rows) throw new ArgumentException(Strings.MismatchedColumnLengths, nameof(column)); } @@ -75,7 +87,7 @@ protected override void InsertItem(int columnIndex, DataFrameColumn column) throw new ArgumentException(string.Format(Strings.DuplicateColumnName, column.Name), nameof(column)); } - RowCount = column.Length; + column.AddOwner(this); _columnNameToIndexDictionary[column.Name] = columnIndex; for (int i = columnIndex + 1; i < Count; i++) @@ -100,7 +112,10 @@ protected override void SetItem(int columnIndex, DataFrameColumn column) } _columnNameToIndexDictionary.Remove(this[columnIndex].Name); _columnNameToIndexDictionary[column.Name] = columnIndex; + + this[columnIndex].RemoveOwner(this); base.SetItem(columnIndex, column); + ColumnsChanged?.Invoke(); } @@ -111,6 +126,8 @@ protected override void RemoveItem(int columnIndex) { _columnNameToIndexDictionary[this[i].Name]--; } + + this[columnIndex].RemoveOwner(this); base.RemoveItem(columnIndex); //Reset RowCount if the last column was removed and dataframe is empty @@ -204,15 +221,15 @@ public PrimitiveDataFrameColumn GetPrimitiveColumn(string name) } /// - /// Gets the with the specified . + /// Gets the with the specified . /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public DateTimeDataFrameColumn GetDateTimeColumn(string name) + public PrimitiveDataFrameColumn GetDateTimeColumn(string name) { DataFrameColumn column = this[name]; - if (column is DateTimeDataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } @@ -255,15 +272,15 @@ public StringDataFrameColumn GetStringColumn(string name) } /// - /// Gets the with the specified . + /// Gets the with the specified . /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public BooleanDataFrameColumn GetBooleanColumn(string name) + public PrimitiveDataFrameColumn GetBooleanColumn(string name) { DataFrameColumn column = this[name]; - if (column is BooleanDataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } @@ -272,15 +289,15 @@ public BooleanDataFrameColumn GetBooleanColumn(string name) } /// - /// Gets the with the specified and attempts to return it as an . If is not of type , an exception is thrown. + /// Gets the with the specified and attempts to return it as an . If is not of type , an exception is thrown. /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public ByteDataFrameColumn GetByteColumn(string name) + public PrimitiveDataFrameColumn GetByteColumn(string name) { DataFrameColumn column = this[name]; - if (column is ByteDataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } @@ -289,15 +306,15 @@ public ByteDataFrameColumn GetByteColumn(string name) } /// - /// Gets the with the specified . + /// Gets the with the specified . /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public CharDataFrameColumn GetCharColumn(string name) + public PrimitiveDataFrameColumn GetCharColumn(string name) { DataFrameColumn column = this[name]; - if (column is CharDataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } @@ -306,15 +323,15 @@ public CharDataFrameColumn GetCharColumn(string name) } /// - /// Gets the with the specified . + /// Gets the with the specified . /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public DoubleDataFrameColumn GetDoubleColumn(string name) + public PrimitiveDataFrameColumn GetDoubleColumn(string name) { DataFrameColumn column = this[name]; - if (column is DoubleDataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } @@ -323,15 +340,15 @@ public DoubleDataFrameColumn GetDoubleColumn(string name) } /// - /// Gets the with the specified . + /// Gets the with the specified . /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public DecimalDataFrameColumn GetDecimalColumn(string name) + public PrimitiveDataFrameColumn GetDecimalColumn(string name) { DataFrameColumn column = this[name]; - if (column is DecimalDataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } @@ -340,15 +357,15 @@ public DecimalDataFrameColumn GetDecimalColumn(string name) } /// - /// Gets the with the specified . + /// Gets the with the specified . /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public SingleDataFrameColumn GetSingleColumn(string name) + public PrimitiveDataFrameColumn GetSingleColumn(string name) { DataFrameColumn column = this[name]; - if (column is SingleDataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } @@ -357,15 +374,15 @@ public SingleDataFrameColumn GetSingleColumn(string name) } /// - /// Gets the with the specified . + /// Gets the with the specified . /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public Int32DataFrameColumn GetInt32Column(string name) + public PrimitiveDataFrameColumn GetInt32Column(string name) { DataFrameColumn column = this[name]; - if (column is Int32DataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } @@ -374,15 +391,15 @@ public Int32DataFrameColumn GetInt32Column(string name) } /// - /// Gets the with the specified . + /// Gets the with the specified . /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public Int64DataFrameColumn GetInt64Column(string name) + public PrimitiveDataFrameColumn GetInt64Column(string name) { DataFrameColumn column = this[name]; - if (column is Int64DataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } @@ -391,15 +408,15 @@ public Int64DataFrameColumn GetInt64Column(string name) } /// - /// Gets the with the specified . + /// Gets the with the specified . /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public SByteDataFrameColumn GetSByteColumn(string name) + public PrimitiveDataFrameColumn GetSByteColumn(string name) { DataFrameColumn column = this[name]; - if (column is SByteDataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } @@ -408,15 +425,15 @@ public SByteDataFrameColumn GetSByteColumn(string name) } /// - /// Gets the with the specified . + /// Gets the with the specified . /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public Int16DataFrameColumn GetInt16Column(string name) + public PrimitiveDataFrameColumn GetInt16Column(string name) { DataFrameColumn column = this[name]; - if (column is Int16DataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } @@ -425,15 +442,15 @@ public Int16DataFrameColumn GetInt16Column(string name) } /// - /// Gets the with the specified . + /// Gets the with the specified . /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public UInt32DataFrameColumn GetUInt32Column(string name) + public PrimitiveDataFrameColumn GetUInt32Column(string name) { DataFrameColumn column = this[name]; - if (column is UInt32DataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } @@ -442,15 +459,15 @@ public UInt32DataFrameColumn GetUInt32Column(string name) } /// - /// Gets the with the specified . + /// Gets the with the specified . /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public UInt64DataFrameColumn GetUInt64Column(string name) + public PrimitiveDataFrameColumn GetUInt64Column(string name) { DataFrameColumn column = this[name]; - if (column is UInt64DataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } @@ -459,15 +476,15 @@ public UInt64DataFrameColumn GetUInt64Column(string name) } /// - /// Gets the with the specified . + /// Gets the with the specified . /// /// The name of the column - /// . + /// . /// A column named cannot be found, or if the column's type doesn't match. - public UInt16DataFrameColumn GetUInt16Column(string name) + public PrimitiveDataFrameColumn GetUInt16Column(string name) { DataFrameColumn column = this[name]; - if (column is UInt16DataFrameColumn ret) + if (column is PrimitiveDataFrameColumn ret) { return ret; } diff --git a/src/Microsoft.Data.Analysis/DateTimeComputation.cs b/src/Microsoft.Data.Analysis/DateTimeComputation.cs index 5335d30f87..4dae3cfd9d 100644 --- a/src/Microsoft.Data.Analysis/DateTimeComputation.cs +++ b/src/Microsoft.Data.Analysis/DateTimeComputation.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.Reflection; using System.Text; namespace Microsoft.Data.Analysis @@ -189,26 +191,35 @@ public void CumulativeSum(PrimitiveColumnContainer column, IEnumerable throw new NotSupportedException(); } - public void Max(PrimitiveColumnContainer column, out DateTime ret) + public void Max(PrimitiveColumnContainer column, out DateTime? ret) { - ret = column.Buffers[0].ReadOnlySpan[0]; + var maxDate = DateTime.MinValue; + bool hasMaxValue = false; + for (int b = 0; b < column.Buffers.Count; b++) { - var buffer = column.Buffers[b]; - var readOnlySpan = buffer.ReadOnlySpan; + var readOnlySpan = column.Buffers[b].ReadOnlySpan; + var bitmapSpan = column.NullBitMapBuffers[b].ReadOnlySpan; for (int i = 0; i < readOnlySpan.Length; i++) { + //Check if bit is not set (value is null) - skip + if (!BitmapHelper.IsValid(bitmapSpan, i)) + continue; + var val = readOnlySpan[i]; - if (val > ret) + if (val > maxDate) { - ret = val; + maxDate = val; + hasMaxValue = true; } } } + + ret = hasMaxValue ? maxDate : null; } - public void Max(PrimitiveColumnContainer column, IEnumerable rows, out DateTime ret) + public void Max(PrimitiveColumnContainer column, IEnumerable rows, out DateTime? ret) { ret = default; var readOnlySpan = column.Buffers[0].ReadOnlySpan; @@ -237,26 +248,36 @@ public void Max(PrimitiveColumnContainer column, IEnumerable row } } - public void Min(PrimitiveColumnContainer column, out DateTime ret) + public void Min(PrimitiveColumnContainer column, out DateTime? ret) { - ret = column.Buffers[0].ReadOnlySpan[0]; + var minDate = DateTime.MaxValue; + bool hasMinValue = false; + for (int b = 0; b < column.Buffers.Count; b++) { - var buffer = column.Buffers[b]; - var readOnlySpan = buffer.ReadOnlySpan; + var readOnlySpan = column.Buffers[b].ReadOnlySpan; + var bitmapSpan = column.NullBitMapBuffers[b].ReadOnlySpan; + for (int i = 0; i < readOnlySpan.Length; i++) { + //Check if bit is not set (value is null) - skip + if (!BitmapHelper.IsValid(bitmapSpan, i)) + continue; + var val = readOnlySpan[i]; - if (val < ret) + if (val < minDate) { - ret = val; + minDate = val; + hasMinValue = true; } } } + + ret = hasMinValue ? minDate : null; } - public void Min(PrimitiveColumnContainer column, IEnumerable rows, out DateTime ret) + public void Min(PrimitiveColumnContainer column, IEnumerable rows, out DateTime? ret) { ret = default; var readOnlySpan = column.Buffers[0].ReadOnlySpan; @@ -285,22 +306,22 @@ public void Min(PrimitiveColumnContainer column, IEnumerable row } } - public void Product(PrimitiveColumnContainer column, out DateTime ret) + public void Product(PrimitiveColumnContainer column, out DateTime? ret) { throw new NotSupportedException(); } - public void Product(PrimitiveColumnContainer column, IEnumerable rows, out DateTime ret) + public void Product(PrimitiveColumnContainer column, IEnumerable rows, out DateTime? ret) { throw new NotSupportedException(); } - public void Sum(PrimitiveColumnContainer column, out DateTime ret) + public void Sum(PrimitiveColumnContainer column, out DateTime? ret) { throw new NotSupportedException(); } - public void Sum(PrimitiveColumnContainer column, IEnumerable rows, out DateTime ret) + public void Sum(PrimitiveColumnContainer column, IEnumerable rows, out DateTime? ret) { throw new NotSupportedException(); } @@ -310,5 +331,9 @@ public void Round(PrimitiveColumnContainer column) throw new NotSupportedException(); } + public PrimitiveColumnContainer CreateTruncating(PrimitiveColumnContainer column) where U : unmanaged, INumber + { + throw new NotImplementedException(); + } } } diff --git a/src/Microsoft.Data.Analysis/DateTimeDataFrameColumn.cs b/src/Microsoft.Data.Analysis/DateTimeDataFrameColumn.cs deleted file mode 100644 index 63d1577fd6..0000000000 --- a/src/Microsoft.Data.Analysis/DateTimeDataFrameColumn.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.Data.Analysis -{ - public partial class DateTimeDataFrameColumn : PrimitiveDataFrameColumn - { - public DateTimeDataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public DateTimeDataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public DateTimeDataFrameColumn(string name, long length = 0) : base(name, length) { } - - public DateTimeDataFrameColumn(string name, ReadOnlyMemory buffer, ReadOnlyMemory nullBitMap, int length = 0, int nullCount = 0) : base(name, buffer, nullBitMap, length, nullCount) { } - - internal DateTimeDataFrameColumn(string name, PrimitiveColumnContainer values) : base(name, values) { } - - protected override PrimitiveDataFrameColumn CreateNewColumn(string name, long length = 0) - { - return new DateTimeDataFrameColumn(name, length); - } - - internal override PrimitiveDataFrameColumn CreateNewColumn(string name, PrimitiveColumnContainer container) - { - return new DateTimeDataFrameColumn(name, container); - } - } -} diff --git a/src/Microsoft.Data.Analysis/DecimalDataFrameColumn.cs b/src/Microsoft.Data.Analysis/DecimalDataFrameColumn.cs deleted file mode 100644 index e39155cd55..0000000000 --- a/src/Microsoft.Data.Analysis/DecimalDataFrameColumn.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.Data.Analysis -{ - public partial class DecimalDataFrameColumn : PrimitiveDataFrameColumn - { - public DecimalDataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public DecimalDataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public DecimalDataFrameColumn(string name, long length = 0) : base(name, length) { } - - public DecimalDataFrameColumn(string name, ReadOnlyMemory buffer, ReadOnlyMemory nullBitMap, int length = 0, int nullCount = 0) : base(name, buffer, nullBitMap, length, nullCount) { } - - internal DecimalDataFrameColumn(string name, PrimitiveColumnContainer values) : base(name, values) { } - - protected override PrimitiveDataFrameColumn CreateNewColumn(string name, long length = 0) - { - return new DecimalDataFrameColumn(name, length); - } - - internal override PrimitiveDataFrameColumn CreateNewColumn(string name, PrimitiveColumnContainer container) - { - return new DecimalDataFrameColumn(name, container); - } - } -} diff --git a/src/Microsoft.Data.Analysis/DecimalMathComputation.cs b/src/Microsoft.Data.Analysis/DecimalMathComputation.cs new file mode 100644 index 0000000000..92db1d40dc --- /dev/null +++ b/src/Microsoft.Data.Analysis/DecimalMathComputation.cs @@ -0,0 +1,23 @@ + + +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// Generated from PrimitiveColumnComputations.tt. Do not modify directly + +using System; +using System.Collections.Generic; +using System.Runtime.Versioning; + +namespace Microsoft.Data.Analysis +{ + [RequiresPreviewFeatures] + internal class DecimalMathComputation : NumberMathComputation + { + public override void Round(PrimitiveColumnContainer column) + { + Apply(column, decimal.Round); + } + } +} diff --git a/src/Microsoft.Data.Analysis/DoubleDataFrameColumn.cs b/src/Microsoft.Data.Analysis/DoubleDataFrameColumn.cs deleted file mode 100644 index 90500eb860..0000000000 --- a/src/Microsoft.Data.Analysis/DoubleDataFrameColumn.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.Data.Analysis -{ - public partial class DoubleDataFrameColumn : PrimitiveDataFrameColumn - { - public DoubleDataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public DoubleDataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public DoubleDataFrameColumn(string name, long length = 0) : base(name, length) { } - - public DoubleDataFrameColumn(string name, ReadOnlyMemory buffer, ReadOnlyMemory nullBitMap, int length = 0, int nullCount = 0) : base(name, buffer, nullBitMap, length, nullCount) { } - - internal DoubleDataFrameColumn(string name, PrimitiveColumnContainer values) : base(name, values) { } - - protected override PrimitiveDataFrameColumn CreateNewColumn(string name, long length = 0) - { - return new DoubleDataFrameColumn(name, length); - } - - internal override PrimitiveDataFrameColumn CreateNewColumn(string name, PrimitiveColumnContainer container) - { - return new DoubleDataFrameColumn(name, container); - } - } -} diff --git a/src/Microsoft.Data.Analysis/FloatingPointDataFrameColumnArithmetic.cs b/src/Microsoft.Data.Analysis/FloatingPointDataFrameColumnArithmetic.cs new file mode 100644 index 0000000000..9a776175d4 --- /dev/null +++ b/src/Microsoft.Data.Analysis/FloatingPointDataFrameColumnArithmetic.cs @@ -0,0 +1,453 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.Data.Analysis +{ + internal class FloatingPointDataFrameColumnArithmetic : IPrimitiveDataFrameColumnArithmetic + where T : unmanaged, INumber + { + public FloatingPointDataFrameColumnArithmetic() : base() + { + } + public void Add(PrimitiveColumnContainer left, PrimitiveColumnContainer right) + { + for (int b = 0; b < left.Buffers.Count; b++) + { + var buffer = left.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + left.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + var otherSpan = right.Buffers[b].ReadOnlySpan; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(span[i] + otherSpan[i]); + } + } + } + public void Add(PrimitiveColumnContainer column, T scalar) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(span[i] + scalar); + } + } + } + public void Add(T scalar, PrimitiveColumnContainer column) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(scalar + span[i]); + } + } + } + public void Subtract(PrimitiveColumnContainer left, PrimitiveColumnContainer right) + { + for (int b = 0; b < left.Buffers.Count; b++) + { + var buffer = left.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + left.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + var otherSpan = right.Buffers[b].ReadOnlySpan; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(span[i] - otherSpan[i]); + } + } + } + public void Subtract(PrimitiveColumnContainer column, T scalar) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(span[i] - scalar); + } + } + } + public void Subtract(T scalar, PrimitiveColumnContainer column) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(scalar - span[i]); + } + } + } + public void Multiply(PrimitiveColumnContainer left, PrimitiveColumnContainer right) + { + for (int b = 0; b < left.Buffers.Count; b++) + { + var buffer = left.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + left.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + var otherSpan = right.Buffers[b].ReadOnlySpan; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(span[i] * otherSpan[i]); + } + } + } + public void Multiply(PrimitiveColumnContainer column, T scalar) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(span[i] * scalar); + } + } + } + public void Multiply(T scalar, PrimitiveColumnContainer column) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(scalar * span[i]); + } + } + } + public void Divide(PrimitiveColumnContainer left, PrimitiveColumnContainer right) + { + for (int b = 0; b < left.Buffers.Count; b++) + { + var buffer = left.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + left.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + var otherSpan = right.Buffers[b].ReadOnlySpan; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(span[i] / otherSpan[i]); + } + } + } + public void Divide(PrimitiveColumnContainer column, T scalar) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(span[i] / scalar); + } + } + } + public void Divide(T scalar, PrimitiveColumnContainer column) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(scalar / span[i]); + } + } + } + public void Modulo(PrimitiveColumnContainer left, PrimitiveColumnContainer right) + { + for (int b = 0; b < left.Buffers.Count; b++) + { + var buffer = left.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + left.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + var otherSpan = right.Buffers[b].ReadOnlySpan; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(span[i] % otherSpan[i]); + } + } + } + public void Modulo(PrimitiveColumnContainer column, T scalar) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(span[i] % scalar); + } + } + } + public void Modulo(T scalar, PrimitiveColumnContainer column) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + span[i] = (T)(scalar % span[i]); + } + } + } + public virtual void And(PrimitiveColumnContainer left, PrimitiveColumnContainer right) + { + throw new NotSupportedException(); + } + public virtual void And(PrimitiveColumnContainer column, T scalar) + { + throw new NotSupportedException(); + } + public virtual void And(T scalar, PrimitiveColumnContainer column) + { + throw new NotSupportedException(); + } + public virtual void Or(PrimitiveColumnContainer left, PrimitiveColumnContainer right) + { + throw new NotSupportedException(); + } + public virtual void Or(PrimitiveColumnContainer column, T scalar) + { + throw new NotSupportedException(); + } + public virtual void Or(T scalar, PrimitiveColumnContainer column) + { + throw new NotSupportedException(); + } + public virtual void Xor(PrimitiveColumnContainer left, PrimitiveColumnContainer right) + { + throw new NotSupportedException(); + } + public virtual void Xor(PrimitiveColumnContainer column, T scalar) + { + throw new NotSupportedException(); + } + public virtual void Xor(T scalar, PrimitiveColumnContainer column) + { + throw new NotSupportedException(); + } + public virtual void LeftShift(PrimitiveColumnContainer column, int value) + { + throw new NotSupportedException(); + } + public virtual void RightShift(PrimitiveColumnContainer column, int value) + { + throw new NotSupportedException(); + } + public void ElementwiseEquals(PrimitiveColumnContainer left, PrimitiveColumnContainer right, PrimitiveColumnContainer ret) + { + for (int b = 0; b < left.Buffers.Count; b++) + { + var buffer = left.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + left.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + var otherSpan = right.Buffers[b].ReadOnlySpan; + for (int i = 0; i < span.Length; i++) + { + ret[i] = (span[i] == otherSpan[i]); + } + } + } + public void ElementwiseEquals(PrimitiveColumnContainer column, T scalar, PrimitiveColumnContainer ret) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + ret[i] = (span[i] == scalar); + } + } + } + public void ElementwiseNotEquals(PrimitiveColumnContainer left, PrimitiveColumnContainer right, PrimitiveColumnContainer ret) + { + for (int b = 0; b < left.Buffers.Count; b++) + { + var buffer = left.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + left.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + var otherSpan = right.Buffers[b].ReadOnlySpan; + for (int i = 0; i < span.Length; i++) + { + ret[i] = (span[i] != otherSpan[i]); + } + } + } + public void ElementwiseNotEquals(PrimitiveColumnContainer column, T scalar, PrimitiveColumnContainer ret) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + ret[i] = (span[i] != scalar); + } + } + } + public void ElementwiseGreaterThanOrEqual(PrimitiveColumnContainer left, PrimitiveColumnContainer right, PrimitiveColumnContainer ret) + { + for (int b = 0; b < left.Buffers.Count; b++) + { + var buffer = left.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + left.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + var otherSpan = right.Buffers[b].ReadOnlySpan; + for (int i = 0; i < span.Length; i++) + { + ret[i] = (span[i] >= otherSpan[i]); + } + } + } + public void ElementwiseGreaterThanOrEqual(PrimitiveColumnContainer column, T scalar, PrimitiveColumnContainer ret) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + ret[i] = (span[i] >= scalar); + } + } + } + public void ElementwiseLessThanOrEqual(PrimitiveColumnContainer left, PrimitiveColumnContainer right, PrimitiveColumnContainer ret) + { + for (int b = 0; b < left.Buffers.Count; b++) + { + var buffer = left.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + left.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + var otherSpan = right.Buffers[b].ReadOnlySpan; + for (int i = 0; i < span.Length; i++) + { + ret[i] = (span[i] <= otherSpan[i]); + } + } + } + public void ElementwiseLessThanOrEqual(PrimitiveColumnContainer column, T scalar, PrimitiveColumnContainer ret) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + ret[i] = (span[i] <= scalar); + } + } + } + public void ElementwiseGreaterThan(PrimitiveColumnContainer left, PrimitiveColumnContainer right, PrimitiveColumnContainer ret) + { + for (int b = 0; b < left.Buffers.Count; b++) + { + var buffer = left.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + left.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + var otherSpan = right.Buffers[b].ReadOnlySpan; + for (int i = 0; i < span.Length; i++) + { + ret[i] = (span[i] > otherSpan[i]); + } + } + } + public void ElementwiseGreaterThan(PrimitiveColumnContainer column, T scalar, PrimitiveColumnContainer ret) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + ret[i] = (span[i] > scalar); + } + } + } + public void ElementwiseLessThan(PrimitiveColumnContainer left, PrimitiveColumnContainer right, PrimitiveColumnContainer ret) + { + for (int b = 0; b < left.Buffers.Count; b++) + { + var buffer = left.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + left.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + var otherSpan = right.Buffers[b].ReadOnlySpan; + for (int i = 0; i < span.Length; i++) + { + ret[i] = (span[i] < otherSpan[i]); + } + } + } + public void ElementwiseLessThan(PrimitiveColumnContainer column, T scalar, PrimitiveColumnContainer ret) + { + for (int b = 0; b < column.Buffers.Count; b++) + { + var buffer = column.Buffers[b]; + var mutableBuffer = DataFrameBuffer.GetMutableBuffer(buffer); + column.Buffers[b] = mutableBuffer; + var span = mutableBuffer.Span; + for (int i = 0; i < span.Length; i++) + { + ret[i] = (span[i] < scalar); + } + } + } + } +} diff --git a/src/Microsoft.Data.Analysis/FloatingPointMathComputation.cs b/src/Microsoft.Data.Analysis/FloatingPointMathComputation.cs new file mode 100644 index 0000000000..e01de94750 --- /dev/null +++ b/src/Microsoft.Data.Analysis/FloatingPointMathComputation.cs @@ -0,0 +1,24 @@ + + +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// Generated from PrimitiveColumnComputations.tt. Do not modify directly + +using System; +using System.Collections.Generic; +using System.Runtime.Versioning; + +namespace Microsoft.Data.Analysis +{ + [RequiresPreviewFeatures] + internal class FloatingPointMathComputation : NumberMathComputation + where T : unmanaged, INumber, IFloatingPoint + { + public override void Round(PrimitiveColumnContainer column) + { + Apply(column, T.Round); + } + } +} diff --git a/src/Microsoft.Data.Analysis/IDataView.Extension.cs b/src/Microsoft.Data.Analysis/IDataView.Extension.cs index 545765f010..d59a465ae0 100644 --- a/src/Microsoft.Data.Analysis/IDataView.Extension.cs +++ b/src/Microsoft.Data.Analysis/IDataView.Extension.cs @@ -66,51 +66,51 @@ public static DataFrame ToDataFrame(this IDataView dataView, long maxRows, param DataViewType type = dataViewColumn.Type; if (type == BooleanDataViewType.Instance) { - dataFrameColumns.Add(new BooleanDataFrameColumn(dataViewColumn.Name)); + dataFrameColumns.Add(new PrimitiveDataFrameColumn(dataViewColumn.Name)); } else if (type == DateTimeDataViewType.Instance) { - dataFrameColumns.Add(new DateTimeDataFrameColumn(dataViewColumn.Name)); + dataFrameColumns.Add(new PrimitiveDataFrameColumn(dataViewColumn.Name)); } else if (type == NumberDataViewType.Byte) { - dataFrameColumns.Add(new ByteDataFrameColumn(dataViewColumn.Name)); + dataFrameColumns.Add(new PrimitiveDataFrameColumn(dataViewColumn.Name)); } else if (type == NumberDataViewType.Double) { - dataFrameColumns.Add(new DoubleDataFrameColumn(dataViewColumn.Name)); + dataFrameColumns.Add(new PrimitiveDataFrameColumn(dataViewColumn.Name)); } else if (type == NumberDataViewType.Single) { - dataFrameColumns.Add(new SingleDataFrameColumn(dataViewColumn.Name)); + dataFrameColumns.Add(new PrimitiveDataFrameColumn(dataViewColumn.Name)); } else if (type == NumberDataViewType.Int32) { - dataFrameColumns.Add(new Int32DataFrameColumn(dataViewColumn.Name)); + dataFrameColumns.Add(new PrimitiveDataFrameColumn(dataViewColumn.Name)); } else if (type == NumberDataViewType.Int64) { - dataFrameColumns.Add(new Int64DataFrameColumn(dataViewColumn.Name)); + dataFrameColumns.Add(new PrimitiveDataFrameColumn(dataViewColumn.Name)); } else if (type == NumberDataViewType.SByte) { - dataFrameColumns.Add(new SByteDataFrameColumn(dataViewColumn.Name)); + dataFrameColumns.Add(new PrimitiveDataFrameColumn(dataViewColumn.Name)); } else if (type == NumberDataViewType.Int16) { - dataFrameColumns.Add(new Int16DataFrameColumn(dataViewColumn.Name)); + dataFrameColumns.Add(new PrimitiveDataFrameColumn(dataViewColumn.Name)); } else if (type == NumberDataViewType.UInt32) { - dataFrameColumns.Add(new UInt32DataFrameColumn(dataViewColumn.Name)); + dataFrameColumns.Add(new PrimitiveDataFrameColumn(dataViewColumn.Name)); } else if (type == NumberDataViewType.UInt64) { - dataFrameColumns.Add(new UInt64DataFrameColumn(dataViewColumn.Name)); + dataFrameColumns.Add(new PrimitiveDataFrameColumn(dataViewColumn.Name)); } else if (type == NumberDataViewType.UInt16) { - dataFrameColumns.Add(new UInt16DataFrameColumn(dataViewColumn.Name)); + dataFrameColumns.Add(new PrimitiveDataFrameColumn(dataViewColumn.Name)); } else if (type == TextDataViewType.Instance) { diff --git a/src/Microsoft.Data.Analysis/IPrimitiveDataFrameColumnArithmetic.cs b/src/Microsoft.Data.Analysis/IPrimitiveDataFrameColumnArithmetic.cs new file mode 100644 index 0000000000..23e178b41a --- /dev/null +++ b/src/Microsoft.Data.Analysis/IPrimitiveDataFrameColumnArithmetic.cs @@ -0,0 +1,51 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// Generated from PrimitiveDataFrameColumnArithmetic.tt. Do not modify directly + +namespace Microsoft.Data.Analysis +{ + internal interface IPrimitiveDataFrameColumnArithmetic + where T : unmanaged + { + void Add(PrimitiveColumnContainer left, PrimitiveColumnContainer right); + void Add(PrimitiveColumnContainer column, T scalar); + void Add(T scalar, PrimitiveColumnContainer column); + void Subtract(PrimitiveColumnContainer left, PrimitiveColumnContainer right); + void Subtract(PrimitiveColumnContainer column, T scalar); + void Subtract(T scalar, PrimitiveColumnContainer column); + void Multiply(PrimitiveColumnContainer left, PrimitiveColumnContainer right); + void Multiply(PrimitiveColumnContainer column, T scalar); + void Multiply(T scalar, PrimitiveColumnContainer column); + void Divide(PrimitiveColumnContainer left, PrimitiveColumnContainer right); + void Divide(PrimitiveColumnContainer column, T scalar); + void Divide(T scalar, PrimitiveColumnContainer column); + void Modulo(PrimitiveColumnContainer left, PrimitiveColumnContainer right); + void Modulo(PrimitiveColumnContainer column, T scalar); + void Modulo(T scalar, PrimitiveColumnContainer column); + void And(PrimitiveColumnContainer left, PrimitiveColumnContainer right); + void And(PrimitiveColumnContainer column, T scalar); + void And(T scalar, PrimitiveColumnContainer column); + void Or(PrimitiveColumnContainer left, PrimitiveColumnContainer right); + void Or(PrimitiveColumnContainer column, T scalar); + void Or(T scalar, PrimitiveColumnContainer column); + void Xor(PrimitiveColumnContainer left, PrimitiveColumnContainer right); + void Xor(PrimitiveColumnContainer column, T scalar); + void Xor(T scalar, PrimitiveColumnContainer column); + void LeftShift(PrimitiveColumnContainer column, int value); + void RightShift(PrimitiveColumnContainer column, int value); + void ElementwiseEquals(PrimitiveColumnContainer left, PrimitiveColumnContainer right, PrimitiveColumnContainer ret); + void ElementwiseEquals(PrimitiveColumnContainer column, T scalar, PrimitiveColumnContainer ret); + void ElementwiseNotEquals(PrimitiveColumnContainer left, PrimitiveColumnContainer right, PrimitiveColumnContainer ret); + void ElementwiseNotEquals(PrimitiveColumnContainer column, T scalar, PrimitiveColumnContainer ret); + void ElementwiseGreaterThanOrEqual(PrimitiveColumnContainer left, PrimitiveColumnContainer right, PrimitiveColumnContainer ret); + void ElementwiseGreaterThanOrEqual(PrimitiveColumnContainer column, T scalar, PrimitiveColumnContainer ret); + void ElementwiseLessThanOrEqual(PrimitiveColumnContainer left, PrimitiveColumnContainer right, PrimitiveColumnContainer ret); + void ElementwiseLessThanOrEqual(PrimitiveColumnContainer column, T scalar, PrimitiveColumnContainer ret); + void ElementwiseGreaterThan(PrimitiveColumnContainer left, PrimitiveColumnContainer right, PrimitiveColumnContainer ret); + void ElementwiseGreaterThan(PrimitiveColumnContainer column, T scalar, PrimitiveColumnContainer ret); + void ElementwiseLessThan(PrimitiveColumnContainer left, PrimitiveColumnContainer right, PrimitiveColumnContainer ret); + void ElementwiseLessThan(PrimitiveColumnContainer column, T scalar, PrimitiveColumnContainer ret); + } +} diff --git a/src/Microsoft.Data.Analysis/Int16DataFrameColumn.cs b/src/Microsoft.Data.Analysis/Int16DataFrameColumn.cs deleted file mode 100644 index c4bdd3ae07..0000000000 --- a/src/Microsoft.Data.Analysis/Int16DataFrameColumn.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.Data.Analysis -{ - public partial class Int16DataFrameColumn : PrimitiveDataFrameColumn - { - public Int16DataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public Int16DataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public Int16DataFrameColumn(string name, long length = 0) : base(name, length) { } - - public Int16DataFrameColumn(string name, ReadOnlyMemory buffer, ReadOnlyMemory nullBitMap, int length = 0, int nullCount = 0) : base(name, buffer, nullBitMap, length, nullCount) { } - - internal Int16DataFrameColumn(string name, PrimitiveColumnContainer values) : base(name, values) { } - - protected override PrimitiveDataFrameColumn CreateNewColumn(string name, long length = 0) - { - return new Int16DataFrameColumn(name, length); - } - - internal override PrimitiveDataFrameColumn CreateNewColumn(string name, PrimitiveColumnContainer container) - { - return new Int16DataFrameColumn(name, container); - } - } -} diff --git a/src/Microsoft.Data.Analysis/Int32DataFrameColumn.cs b/src/Microsoft.Data.Analysis/Int32DataFrameColumn.cs deleted file mode 100644 index bd80092db7..0000000000 --- a/src/Microsoft.Data.Analysis/Int32DataFrameColumn.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.Data.Analysis -{ - public partial class Int32DataFrameColumn : PrimitiveDataFrameColumn - { - public Int32DataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public Int32DataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public Int32DataFrameColumn(string name, long length = 0) : base(name, length) { } - - public Int32DataFrameColumn(string name, ReadOnlyMemory buffer, ReadOnlyMemory nullBitMap, int length = 0, int nullCount = 0) : base(name, buffer, nullBitMap, length, nullCount) { } - - internal Int32DataFrameColumn(string name, PrimitiveColumnContainer values) : base(name, values) { } - - protected override PrimitiveDataFrameColumn CreateNewColumn(string name, long length = 0) - { - return new Int32DataFrameColumn(name, length); - } - - internal override PrimitiveDataFrameColumn CreateNewColumn(string name, PrimitiveColumnContainer container) - { - return new Int32DataFrameColumn(name, container); - } - } -} diff --git a/src/Microsoft.Data.Analysis/Int64DataFrameColumn.cs b/src/Microsoft.Data.Analysis/Int64DataFrameColumn.cs deleted file mode 100644 index 2bea8c8630..0000000000 --- a/src/Microsoft.Data.Analysis/Int64DataFrameColumn.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.Data.Analysis -{ - public partial class Int64DataFrameColumn : PrimitiveDataFrameColumn - { - public Int64DataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public Int64DataFrameColumn(string name, IEnumerable values) : base(name, values) { } - - public Int64DataFrameColumn(string name, long length = 0) : base(name, length) { } - - public Int64DataFrameColumn(string name, ReadOnlyMemory buffer, ReadOnlyMemory nullBitMap, int length = 0, int nullCount = 0) : base(name, buffer, nullBitMap, length, nullCount) { } - - internal Int64DataFrameColumn(string name, PrimitiveColumnContainer values) : base(name, values) { } - - protected override PrimitiveDataFrameColumn CreateNewColumn(string name, long length = 0) - { - return new Int64DataFrameColumn(name, length); - } - - internal override PrimitiveDataFrameColumn CreateNewColumn(string name, PrimitiveColumnContainer container) - { - return new Int64DataFrameColumn(name, container); - } - } -} diff --git a/src/Microsoft.Data.Analysis/Microsoft.Data.Analysis.csproj b/src/Microsoft.Data.Analysis/Microsoft.Data.Analysis.csproj index acfcd62199..0b2333c442 100644 --- a/src/Microsoft.Data.Analysis/Microsoft.Data.Analysis.csproj +++ b/src/Microsoft.Data.Analysis/Microsoft.Data.Analysis.csproj @@ -1,13 +1,16 @@  - netstandard2.0 + net6.0 + True true false This package contains easy-to-use and high-performance libraries for data analysis and transformation. Initial preview of robust and extensible types and algorithms for manipulating structured data that supports aggregations, statistical funtions, sorting, grouping, joins, merges, handling missing values and more. ML.NET ML Machine Learning Data Science DataFrame Preparation DataView Analytics Exploration true + + None diff --git a/test/Microsoft.ML.Core.Tests/Microsoft.ML.Core.Tests.csproj b/test/Microsoft.ML.Core.Tests/Microsoft.ML.Core.Tests.csproj index 475eb5dbb1..49fddcd74f 100644 --- a/test/Microsoft.ML.Core.Tests/Microsoft.ML.Core.Tests.csproj +++ b/test/Microsoft.ML.Core.Tests/Microsoft.ML.Core.Tests.csproj @@ -8,6 +8,8 @@ None + net6.0 + net6.0 diff --git a/test/Microsoft.ML.Fairlearn.Tests/Microsoft.ML.Fairlearn.Tests.csproj b/test/Microsoft.ML.Fairlearn.Tests/Microsoft.ML.Fairlearn.Tests.csproj index b950086278..90850d97af 100644 --- a/test/Microsoft.ML.Fairlearn.Tests/Microsoft.ML.Fairlearn.Tests.csproj +++ b/test/Microsoft.ML.Fairlearn.Tests/Microsoft.ML.Fairlearn.Tests.csproj @@ -2,6 +2,8 @@ None $(NoWarn);MSML_ParameterLocalVarName;MSML_PrivateFieldName;MSML_ExtendBaseTestClass;MSML_GeneralName + net6.0 + net6.0 diff --git a/test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj b/test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj index c50abd3350..e933dc2f86 100644 --- a/test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj +++ b/test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj @@ -1,6 +1,8 @@  + net6.0 + net6.0 Microsoft.ML.Tests true Test