Skip to content

Commit 50e5068

Browse files
author
Becca McHenry
authored
DataFrame: Add DateTime column type (#6302)
* add DateTime type * datetime computation changes * update primitivedataframe.tt * pr cleanup * update binaryoperations * re-generate all .tt files * add DateTime computation comment * remove the unecessary CloneAsDateTime * add more equality test support
1 parent 2fa7d12 commit 50e5068

19 files changed

+649
-193
lines changed

src/Microsoft.Data.Analysis/ColumnArithmeticTemplate.ttinclude

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@
150150
new TypeConfiguration("short", unsupportedMethods: new[] {"All", "Any"}),
151151
new TypeConfiguration("uint", classPrefix:"UInt", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}),
152152
new TypeConfiguration("ulong", classPrefix:"ULong", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}),
153-
new TypeConfiguration("ushort", classPrefix:"UShort", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"})
153+
new TypeConfiguration("ushort", classPrefix:"UShort", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"}),
154+
new TypeConfiguration("DateTime", supportsBitwise: false, supportsNumeric: false, unsupportedMethods: new[] {"And", "Or", "Xor"})
154155
};
155156

156157
public string GetBinaryShiftOperationReturnType(TypeConfiguration t1)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Text;
8+
9+
namespace Microsoft.Data.Analysis
10+
{
11+
public partial class DateTimeDataFrameColumn : PrimitiveDataFrameColumn<DateTime>
12+
{
13+
public DateTimeDataFrameColumn(string name, IEnumerable<DateTime?> values) : base(name, values) { }
14+
15+
public DateTimeDataFrameColumn(string name, IEnumerable<DateTime> values) : base(name, values) { }
16+
17+
public DateTimeDataFrameColumn(string name, long length = 0) : base(name, length) { }
18+
19+
public DateTimeDataFrameColumn(string name, ReadOnlyMemory<byte> buffer, ReadOnlyMemory<byte> nullBitMap, int length = 0, int nullCount = 0) : base(name, buffer, nullBitMap, length, nullCount) { }
20+
21+
internal DateTimeDataFrameColumn(string name, PrimitiveColumnContainer<DateTime> values) : base(name, values) { }
22+
}
23+
}

src/Microsoft.Data.Analysis/IDataView.Extension.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public static DataFrame ToDataFrame(this IDataView dataView, long maxRows, param
6868
{
6969
dataFrameColumns.Add(new BooleanDataFrameColumn(dataViewColumn.Name));
7070
}
71+
else if (type == DateTimeDataViewType.Instance)
72+
{
73+
dataFrameColumns.Add(new DateTimeDataFrameColumn(dataViewColumn.Name));
74+
}
7175
else if (type == NumberDataViewType.Byte)
7276
{
7377
dataFrameColumns.Add(new ByteDataFrameColumn(dataViewColumn.Name));

src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperationAPIs.ExplodedColumns.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12248,6 +12248,33 @@ public BooleanDataFrameColumn ElementwiseLessThan(UInt16DataFrameColumn column)
1224812248
return ElementwiseLessThanImplementation(column);
1224912249
}
1225012250
}
12251+
public partial class DateTimeDataFrameColumn
12252+
{
12253+
public BooleanDataFrameColumn ElementwiseEquals(DateTimeDataFrameColumn column)
12254+
{
12255+
return ElementwiseEqualsImplementation(column);
12256+
}
12257+
public BooleanDataFrameColumn ElementwiseNotEquals(DateTimeDataFrameColumn column)
12258+
{
12259+
return ElementwiseNotEqualsImplementation(column);
12260+
}
12261+
public BooleanDataFrameColumn ElementwiseGreaterThanOrEqual(DateTimeDataFrameColumn column)
12262+
{
12263+
return ElementwiseGreaterThanOrEqualImplementation(column);
12264+
}
12265+
public BooleanDataFrameColumn ElementwiseLessThanOrEqual(DateTimeDataFrameColumn column)
12266+
{
12267+
return ElementwiseLessThanOrEqualImplementation(column);
12268+
}
12269+
public BooleanDataFrameColumn ElementwiseGreaterThan(DateTimeDataFrameColumn column)
12270+
{
12271+
return ElementwiseGreaterThanImplementation(column);
12272+
}
12273+
public BooleanDataFrameColumn ElementwiseLessThan(DateTimeDataFrameColumn column)
12274+
{
12275+
return ElementwiseLessThanImplementation(column);
12276+
}
12277+
}
1225112278
public partial class BooleanDataFrameColumn
1225212279
{
1225312280
public BooleanDataFrameColumn ElementwiseEquals(bool value)
@@ -15692,6 +15719,33 @@ public BooleanDataFrameColumn ElementwiseLessThan(ushort value)
1569215719
return ElementwiseLessThanImplementation(value);
1569315720
}
1569415721
}
15722+
public partial class DateTimeDataFrameColumn
15723+
{
15724+
public BooleanDataFrameColumn ElementwiseEquals(DateTime value)
15725+
{
15726+
return ElementwiseEqualsImplementation(value);
15727+
}
15728+
public BooleanDataFrameColumn ElementwiseNotEquals(DateTime value)
15729+
{
15730+
return ElementwiseNotEqualsImplementation(value);
15731+
}
15732+
public BooleanDataFrameColumn ElementwiseGreaterThanOrEqual(DateTime value)
15733+
{
15734+
return ElementwiseGreaterThanOrEqualImplementation(value);
15735+
}
15736+
public BooleanDataFrameColumn ElementwiseLessThanOrEqual(DateTime value)
15737+
{
15738+
return ElementwiseLessThanOrEqualImplementation(value);
15739+
}
15740+
public BooleanDataFrameColumn ElementwiseGreaterThan(DateTime value)
15741+
{
15742+
return ElementwiseGreaterThanImplementation(value);
15743+
}
15744+
public BooleanDataFrameColumn ElementwiseLessThan(DateTime value)
15745+
{
15746+
return ElementwiseLessThanImplementation(value);
15747+
}
15748+
}
1569515749

1569615750
public partial class ByteDataFrameColumn
1569715751
{

src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperationImplementations.Exploded.cs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,15 @@ internal BooleanDataFrameColumn ElementwiseEqualsImplementation(UInt16DataFrameC
12041204
return newColumn;
12051205
}
12061206
}
1207+
public partial class DateTimeDataFrameColumn
1208+
{
1209+
internal BooleanDataFrameColumn ElementwiseEqualsImplementation(DateTimeDataFrameColumn column)
1210+
{
1211+
BooleanDataFrameColumn newColumn = CloneAsBooleanColumn();
1212+
ColumnContainer.ElementwiseEquals(column.ColumnContainer, newColumn.ColumnContainer);
1213+
return newColumn;
1214+
}
1215+
}
12071216
public partial class BooleanDataFrameColumn
12081217
{
12091218
internal BooleanDataFrameColumn ElementwiseEqualsImplementation(bool value)
@@ -1312,6 +1321,15 @@ internal BooleanDataFrameColumn ElementwiseEqualsImplementation(ushort value)
13121321
return newColumn;
13131322
}
13141323
}
1324+
public partial class DateTimeDataFrameColumn
1325+
{
1326+
internal BooleanDataFrameColumn ElementwiseEqualsImplementation(DateTime value)
1327+
{
1328+
BooleanDataFrameColumn newColumn = CloneAsBooleanColumn();
1329+
ColumnContainer.ElementwiseEquals(value, newColumn.ColumnContainer);
1330+
return newColumn;
1331+
}
1332+
}
13151333
public partial class BooleanDataFrameColumn
13161334
{
13171335
internal BooleanDataFrameColumn ElementwiseNotEqualsImplementation(BooleanDataFrameColumn column)
@@ -1420,6 +1438,15 @@ internal BooleanDataFrameColumn ElementwiseNotEqualsImplementation(UInt16DataFra
14201438
return newColumn;
14211439
}
14221440
}
1441+
public partial class DateTimeDataFrameColumn
1442+
{
1443+
internal BooleanDataFrameColumn ElementwiseNotEqualsImplementation(DateTimeDataFrameColumn column)
1444+
{
1445+
BooleanDataFrameColumn newColumn = CloneAsBooleanColumn();
1446+
ColumnContainer.ElementwiseNotEquals(column.ColumnContainer, newColumn.ColumnContainer);
1447+
return newColumn;
1448+
}
1449+
}
14231450
public partial class BooleanDataFrameColumn
14241451
{
14251452
internal BooleanDataFrameColumn ElementwiseNotEqualsImplementation(bool value)
@@ -1528,6 +1555,15 @@ internal BooleanDataFrameColumn ElementwiseNotEqualsImplementation(ushort value)
15281555
return newColumn;
15291556
}
15301557
}
1558+
public partial class DateTimeDataFrameColumn
1559+
{
1560+
internal BooleanDataFrameColumn ElementwiseNotEqualsImplementation(DateTime value)
1561+
{
1562+
BooleanDataFrameColumn newColumn = CloneAsBooleanColumn();
1563+
ColumnContainer.ElementwiseNotEquals(value, newColumn.ColumnContainer);
1564+
return newColumn;
1565+
}
1566+
}
15311567
public partial class BooleanDataFrameColumn
15321568
{
15331569
internal BooleanDataFrameColumn ElementwiseGreaterThanOrEqualImplementation(BooleanDataFrameColumn column)
@@ -1636,6 +1672,15 @@ internal BooleanDataFrameColumn ElementwiseGreaterThanOrEqualImplementation(UInt
16361672
return newColumn;
16371673
}
16381674
}
1675+
public partial class DateTimeDataFrameColumn
1676+
{
1677+
internal BooleanDataFrameColumn ElementwiseGreaterThanOrEqualImplementation(DateTimeDataFrameColumn column)
1678+
{
1679+
BooleanDataFrameColumn newColumn = CloneAsBooleanColumn();
1680+
ColumnContainer.ElementwiseGreaterThanOrEqual(column.ColumnContainer, newColumn.ColumnContainer);
1681+
return newColumn;
1682+
}
1683+
}
16391684
public partial class BooleanDataFrameColumn
16401685
{
16411686
internal BooleanDataFrameColumn ElementwiseGreaterThanOrEqualImplementation(bool value)
@@ -1744,6 +1789,15 @@ internal BooleanDataFrameColumn ElementwiseGreaterThanOrEqualImplementation(usho
17441789
return newColumn;
17451790
}
17461791
}
1792+
public partial class DateTimeDataFrameColumn
1793+
{
1794+
internal BooleanDataFrameColumn ElementwiseGreaterThanOrEqualImplementation(DateTime value)
1795+
{
1796+
BooleanDataFrameColumn newColumn = CloneAsBooleanColumn();
1797+
ColumnContainer.ElementwiseGreaterThanOrEqual(value, newColumn.ColumnContainer);
1798+
return newColumn;
1799+
}
1800+
}
17471801
public partial class BooleanDataFrameColumn
17481802
{
17491803
internal BooleanDataFrameColumn ElementwiseLessThanOrEqualImplementation(BooleanDataFrameColumn column)
@@ -1852,6 +1906,15 @@ internal BooleanDataFrameColumn ElementwiseLessThanOrEqualImplementation(UInt16D
18521906
return newColumn;
18531907
}
18541908
}
1909+
public partial class DateTimeDataFrameColumn
1910+
{
1911+
internal BooleanDataFrameColumn ElementwiseLessThanOrEqualImplementation(DateTimeDataFrameColumn column)
1912+
{
1913+
BooleanDataFrameColumn newColumn = CloneAsBooleanColumn();
1914+
ColumnContainer.ElementwiseLessThanOrEqual(column.ColumnContainer, newColumn.ColumnContainer);
1915+
return newColumn;
1916+
}
1917+
}
18551918
public partial class BooleanDataFrameColumn
18561919
{
18571920
internal BooleanDataFrameColumn ElementwiseLessThanOrEqualImplementation(bool value)
@@ -1960,6 +2023,15 @@ internal BooleanDataFrameColumn ElementwiseLessThanOrEqualImplementation(ushort
19602023
return newColumn;
19612024
}
19622025
}
2026+
public partial class DateTimeDataFrameColumn
2027+
{
2028+
internal BooleanDataFrameColumn ElementwiseLessThanOrEqualImplementation(DateTime value)
2029+
{
2030+
BooleanDataFrameColumn newColumn = CloneAsBooleanColumn();
2031+
ColumnContainer.ElementwiseLessThanOrEqual(value, newColumn.ColumnContainer);
2032+
return newColumn;
2033+
}
2034+
}
19632035
public partial class BooleanDataFrameColumn
19642036
{
19652037
internal BooleanDataFrameColumn ElementwiseGreaterThanImplementation(BooleanDataFrameColumn column)
@@ -2068,6 +2140,15 @@ internal BooleanDataFrameColumn ElementwiseGreaterThanImplementation(UInt16DataF
20682140
return newColumn;
20692141
}
20702142
}
2143+
public partial class DateTimeDataFrameColumn
2144+
{
2145+
internal BooleanDataFrameColumn ElementwiseGreaterThanImplementation(DateTimeDataFrameColumn column)
2146+
{
2147+
BooleanDataFrameColumn newColumn = CloneAsBooleanColumn();
2148+
ColumnContainer.ElementwiseGreaterThan(column.ColumnContainer, newColumn.ColumnContainer);
2149+
return newColumn;
2150+
}
2151+
}
20712152
public partial class BooleanDataFrameColumn
20722153
{
20732154
internal BooleanDataFrameColumn ElementwiseGreaterThanImplementation(bool value)
@@ -2176,6 +2257,15 @@ internal BooleanDataFrameColumn ElementwiseGreaterThanImplementation(ushort valu
21762257
return newColumn;
21772258
}
21782259
}
2260+
public partial class DateTimeDataFrameColumn
2261+
{
2262+
internal BooleanDataFrameColumn ElementwiseGreaterThanImplementation(DateTime value)
2263+
{
2264+
BooleanDataFrameColumn newColumn = CloneAsBooleanColumn();
2265+
ColumnContainer.ElementwiseGreaterThan(value, newColumn.ColumnContainer);
2266+
return newColumn;
2267+
}
2268+
}
21792269
public partial class BooleanDataFrameColumn
21802270
{
21812271
internal BooleanDataFrameColumn ElementwiseLessThanImplementation(BooleanDataFrameColumn column)
@@ -2284,6 +2374,15 @@ internal BooleanDataFrameColumn ElementwiseLessThanImplementation(UInt16DataFram
22842374
return newColumn;
22852375
}
22862376
}
2377+
public partial class DateTimeDataFrameColumn
2378+
{
2379+
internal BooleanDataFrameColumn ElementwiseLessThanImplementation(DateTimeDataFrameColumn column)
2380+
{
2381+
BooleanDataFrameColumn newColumn = CloneAsBooleanColumn();
2382+
ColumnContainer.ElementwiseLessThan(column.ColumnContainer, newColumn.ColumnContainer);
2383+
return newColumn;
2384+
}
2385+
}
22872386
public partial class BooleanDataFrameColumn
22882387
{
22892388
internal BooleanDataFrameColumn ElementwiseLessThanImplementation(bool value)
@@ -2392,4 +2491,13 @@ internal BooleanDataFrameColumn ElementwiseLessThanImplementation(ushort value)
23922491
return newColumn;
23932492
}
23942493
}
2494+
public partial class DateTimeDataFrameColumn
2495+
{
2496+
internal BooleanDataFrameColumn ElementwiseLessThanImplementation(DateTime value)
2497+
{
2498+
BooleanDataFrameColumn newColumn = CloneAsBooleanColumn();
2499+
ColumnContainer.ElementwiseLessThan(value, newColumn.ColumnContainer);
2500+
return newColumn;
2501+
}
2502+
}
23952503
}

src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.Combinations.tt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,15 @@ public static class ComparisonOperationCombinations
8686
{
8787
continue;
8888
}
89+
// Bool should only compare with bool, DateTime only with DateTime
8990
if (type.TypeName == "bool" && innerType.TypeName != "bool")
9091
{
9192
continue;
9293
}
94+
if (type.TypeName == "DateTime" && innerType.TypeName != "DateTime")
95+
{
96+
continue;
97+
}
9398
if (type.SupportsNumeric != innerType.SupportsNumeric)
9499
{
95100
continue;

src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.Combinations.ttinclude

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ public static class ComparisonOperationCombinations
266266
new TypeCombination("ushort", "uint", "bool"),
267267
new TypeCombination("ushort", "ulong", "bool"),
268268
new TypeCombination("ushort", "ushort", "bool"),
269+
new TypeCombination("DateTime", "DateTime", "bool"),
269270
};
270271
}
271272
#>

0 commit comments

Comments
 (0)