@@ -32,7 +32,10 @@ namespace Microsoft.ML.AutoMLFeaturizers
32
32
public static class DateTimeTransformerExtensionClass
33
33
{
34
34
public static DateTimeTransformerEstimator DateTimeTransformer ( this TransformsCatalog catalog , string inputColumnName , string columnPrefix , params DateTimeTransformerEstimator . ColumnsProduced [ ] columnsToDrop )
35
- => DateTimeTransformerEstimator . Create ( CatalogUtils . GetEnvironment ( catalog ) , inputColumnName , columnPrefix , columnsToDrop ) ;
35
+ => new DateTimeTransformerEstimator ( CatalogUtils . GetEnvironment ( catalog ) , inputColumnName , columnPrefix , columnsToDrop ) ;
36
+
37
+ public static DateTimeTransformerEstimator DateTimeTransformer ( this TransformsCatalog catalog , string inputColumnName , string columnPrefix , DateTimeTransformerEstimator . ColumnsProduced [ ] columnsToDrop = null , DateTimeTransformerEstimator . Countries country = DateTimeTransformerEstimator . Countries . None )
38
+ => new DateTimeTransformerEstimator ( CatalogUtils . GetEnvironment ( catalog ) , inputColumnName , columnPrefix , columnsToDrop , country ) ;
36
39
37
40
#region ColumnsProduced static extentions
38
41
@@ -77,21 +80,19 @@ internal sealed class Options: TransformInputBase
77
80
78
81
[ Argument ( ArgumentType . MultipleUnique , HelpText = "Columns to drop after the DateTime Expansion" , Name = "ColumnsToDrop" , ShortName = "drop" , SortOrder = 3 ) ]
79
82
public ColumnsProduced [ ] ColumnsToDrop ;
83
+
84
+ [ Argument ( ArgumentType . AtMostOnce , HelpText = "Country to get holidays for. Defaults to none if not passed" , Name = "Country" , ShortName = "ctry" , SortOrder = 4 ) ]
85
+ public Countries Country = Countries . None ;
80
86
}
81
87
82
88
#endregion
83
89
84
- internal static DateTimeTransformerEstimator Create ( IHostEnvironment env , string inputColumnName , string columnPrefix , ColumnsProduced [ ] columnsToDrop )
85
- {
86
- return new DateTimeTransformerEstimator ( env , inputColumnName , columnPrefix , columnsToDrop ) ;
87
- }
88
-
89
90
// Using this to confirm DLL exists. If does it will just return false since no parameters are being passed.
90
91
// Once we have a binary dependency on the dll we can remove this code.
91
92
[ DllImport ( "Featurizers" , EntryPoint = "GetErrorInfoString" ) , SuppressUnmanagedCodeSecurity ]
92
93
private static extern bool CheckIfDllExists ( IntPtr error , out IntPtr errorHandleString , out IntPtr errorHandleStringSize ) ;
93
94
94
- public DateTimeTransformerEstimator ( IHostEnvironment env , string inputColumnName , string columnPrefix , ColumnsProduced [ ] columnsToDrop )
95
+ public DateTimeTransformerEstimator ( IHostEnvironment env , string inputColumnName , string columnPrefix , ColumnsProduced [ ] columnsToDrop , Countries country = Countries . None )
95
96
{
96
97
try
97
98
{
@@ -110,7 +111,8 @@ public DateTimeTransformerEstimator(IHostEnvironment env, string inputColumnName
110
111
{
111
112
Source = inputColumnName ,
112
113
Prefix = columnPrefix ,
113
- ColumnsToDrop = columnsToDrop
114
+ ColumnsToDrop = columnsToDrop == null ? Array . Empty < ColumnsProduced > ( ) : columnsToDrop ,
115
+ Country = country
114
116
} ;
115
117
}
116
118
@@ -129,6 +131,7 @@ internal DateTimeTransformerEstimator(IHostEnvironment env, Options options)
129
131
_host = Contracts . CheckRef ( env , nameof ( env ) ) . Register ( "DateTimeTransformerEstimator" ) ;
130
132
131
133
_options = options ;
134
+ _options . ColumnsToDrop = _options . ColumnsToDrop == null ? Array . Empty < ColumnsProduced > ( ) : _options . ColumnsToDrop ;
132
135
}
133
136
134
137
public DateTimeTransformer Fit ( IDataView input )
@@ -151,14 +154,23 @@ public SchemaShape GetOutputSchema(SchemaShape inputSchema)
151
154
return new SchemaShape ( columns . Values ) ;
152
155
}
153
156
154
- #region Column Enums
157
+ #region Enums
155
158
public enum ColumnsProduced : byte
156
159
{
157
- Year = 0 , Month , Day , Hour , Minute , Second , AmPm , Hour12 , DayOfWeek , DayOfQuarter , DayOfYear ,
160
+ Year = 1 , Month , Day , Hour , Minute , Second , AmPm , Hour12 , DayOfWeek , DayOfQuarter , DayOfYear ,
158
161
WeekOfMonth , QuarterOfYear , HalfOfYear , WeekIso , YearIso , MonthLabel , AmPmLabel , DayOfWeekLabel ,
159
162
HolidayName , IsPaidTimeOff
160
163
} ;
161
164
165
+ public enum Countries : byte
166
+ {
167
+ None = 1 ,
168
+ Argentina , Australia , Austria , Belarus , Belgium , Brazil , Canada , Colombia , Croatia , Czech , Denmark ,
169
+ England , Finland , France , Germany , Hungary , India , Ireland , IsleofMan , Italy , Japan , Mexico , Netherlands ,
170
+ NewZealand , NorthernIreland , Norway , Poland , Portugal , Scotland , Slovenia , SouthAfrica , Spain , Sweden , Switzerland ,
171
+ Ukraine , UnitedKingdom , UnitedStates , Wales
172
+ }
173
+
162
174
#endregion
163
175
}
164
176
@@ -473,14 +485,17 @@ internal unsafe TimePoint(byte* rawData)
473
485
private static unsafe string GetStringFromPointer( ref byte * rawData , int intPtrSize )
474
486
{
475
487
byte [ ] buffer ;
476
- byte * temp = rawData + intPtrSize ;
477
- long tempSize = * ( long * ) ( temp ) ;
478
- int itempSize = * ( int * ) ( temp ) ;
479
488
if ( intPtrSize = = 4 ) // 32 bit machine
480
489
buffer = new byte [ * ( uint * ) ( rawData + intPtrSize ) ] ;
481
490
else // 64 bit machine
482
491
buffer = new byte [ * ( ulong * ) ( rawData + intPtrSize ) ] ;
483
492
493
+ if ( buffer . Length == 0 )
494
+ {
495
+ rawData += intPtrSize * 2 ;
496
+ return string . Empty ;
497
+ }
498
+
484
499
Marshal . Copy ( new IntPtr ( * ( int * * ) rawData ) , buffer, 0 , buffer. Length ) ;
485
500
rawData += intPtrSize * 2 ;
486
501
@@ -802,7 +817,7 @@ internal static class DateTimeTransformerEntrypoint
802
817
public static CommonOutputs . TransformOutput DateTimeSplit ( IHostEnvironment env , DateTimeTransformerEstimator . Options input )
803
818
{
804
819
var h = EntryPointUtils . CheckArgsAndCreateHost ( env , DateTimeTransformer . ShortName , input ) ;
805
- var xf = DateTimeTransformerEstimator . Create ( h , input . Source , input . Prefix , input . ColumnsToDrop ) . Fit ( input . Data ) . Transform ( input . Data ) ;
820
+ var xf = new DateTimeTransformerEstimator ( h , input ) . Fit ( input . Data ) . Transform ( input . Data ) ;
806
821
return new CommonOutputs . TransformOutput ( )
807
822
{
808
823
Model = new TransformModelImpl ( h , xf , input . Data ) ,
0 commit comments