@@ -20,28 +20,28 @@ namespace Microsoft.ML.Runtime.Data
20
20
/// <include file='doc.xml' path='doc/members/member[@name="NAHandle"]'/>
21
21
public static class NAHandleTransform
22
22
{
23
- public enum ReplacementKind
23
+ public enum ReplacementKind : byte
24
24
{
25
25
/// <summary>
26
26
/// Replace with the default value of the column based on it's type. For example, 'zero' for numeric and 'empty' for string/text columns.
27
27
/// </summary>
28
28
[ EnumValueDisplay ( "Zero/empty" ) ]
29
- DefaultValue ,
29
+ DefaultValue = 0 ,
30
30
31
31
/// <summary>
32
32
/// Replace with the mean value of the column. Supports only numeric/time span/ DateTime columns.
33
33
/// </summary>
34
- Mean ,
34
+ Mean = 1 ,
35
35
36
36
/// <summary>
37
37
/// Replace with the minimum value of the column. Supports only numeric/time span/ DateTime columns.
38
38
/// </summary>
39
- Minimum ,
39
+ Minimum = 2 ,
40
40
41
41
/// <summary>
42
42
/// Replace with the maximum value of the column. Supports only numeric/time span/ DateTime columns.
43
43
/// </summary>
44
- Maximum ,
44
+ Maximum = 3 ,
45
45
46
46
[ HideEnumValue ]
47
47
Def = DefaultValue ,
@@ -135,7 +135,7 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
135
135
h . CheckValue ( input , nameof ( input ) ) ;
136
136
h . CheckUserArg ( Utils . Size ( args . Column ) > 0 , nameof ( args . Column ) ) ;
137
137
138
- var replaceCols = new List < NAReplaceTransform . Column > ( ) ;
138
+ var replaceCols = new List < NAReplaceTransform . ColumnInfo > ( ) ;
139
139
var naIndicatorCols = new List < NAIndicatorTransform . Column > ( ) ;
140
140
var naConvCols = new List < ConvertTransform . Column > ( ) ;
141
141
var concatCols = new List < ConcatTransform . TaggedColumn > ( ) ;
@@ -149,26 +149,16 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
149
149
var addInd = column . ConcatIndicator ?? args . Concat ;
150
150
if ( ! addInd )
151
151
{
152
- replaceCols . Add (
153
- new NAReplaceTransform . Column ( )
154
- {
155
- Kind = ( NAReplaceTransform . ReplacementKind ? ) column . Kind ,
156
- Name = column . Name ,
157
- Source = column . Source ,
158
- Slot = column . ImputeBySlot
159
- } ) ;
152
+ replaceCols . Add ( new NAReplaceTransform . ColumnInfo ( column . Source , column . Name , ( NAReplaceTransform . ColumnInfo . ReplacementMode ) ( column . Kind ?? args . ReplaceWith ) , column . ImputeBySlot ?? args . ImputeBySlot ) ) ;
160
153
continue ;
161
154
}
162
155
163
156
// Check that the indicator column has a type that can be converted to the NAReplaceTransform output type,
164
157
// so that they can be concatenated.
165
- int inputCol ;
166
- if ( ! input . Schema . TryGetColumnIndex ( column . Source , out inputCol ) )
158
+ if ( ! input . Schema . TryGetColumnIndex ( column . Source , out int inputCol ) )
167
159
throw h . Except ( "Column '{0}' does not exist" , column . Source ) ;
168
160
var replaceType = input . Schema . GetColumnType ( inputCol ) ;
169
- Delegate conv ;
170
- bool identity ;
171
- if ( ! Conversions . Instance . TryGetStandardConversion ( BoolType . Instance , replaceType . ItemType , out conv , out identity ) )
161
+ if ( ! Conversions . Instance . TryGetStandardConversion ( BoolType . Instance , replaceType . ItemType , out Delegate conv , out bool identity ) )
172
162
{
173
163
throw h . Except ( "Cannot concatenate indicator column of type '{0}' to input column of type '{1}'" ,
174
164
BoolType . Instance , replaceType . ItemType ) ;
@@ -186,14 +176,7 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
186
176
naConvCols . Add ( new ConvertTransform . Column ( ) { Name = tmpIsMissingColName , Source = tmpIsMissingColName , ResultType = replaceType . ItemType . RawKind } ) ;
187
177
188
178
// Add the NAReplaceTransform column.
189
- replaceCols . Add (
190
- new NAReplaceTransform . Column ( )
191
- {
192
- Kind = ( NAReplaceTransform . ReplacementKind ? ) column . Kind ,
193
- Name = tmpReplacementColName ,
194
- Source = column . Source ,
195
- Slot = column . ImputeBySlot
196
- } ) ;
179
+ replaceCols . Add ( new NAReplaceTransform . ColumnInfo ( column . Source , tmpReplacementColName , ( NAReplaceTransform . ColumnInfo . ReplacementMode ) ( column . Kind ?? args . ReplaceWith ) , column . ImputeBySlot ?? args . ImputeBySlot ) ) ;
197
180
198
181
// Add the ConcatTransform column.
199
182
if ( replaceType . IsVector )
@@ -237,15 +220,8 @@ public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataV
237
220
h . AssertValue ( output ) ;
238
221
output = new ConvertTransform ( h , new ConvertTransform . Arguments ( ) { Column = naConvCols . ToArray ( ) } , output ) ;
239
222
}
240
-
241
223
// Create the NAReplace transform.
242
- output = new NAReplaceTransform ( h ,
243
- new NAReplaceTransform . Arguments ( )
244
- {
245
- Column = replaceCols . ToArray ( ) ,
246
- ReplacementKind = ( NAReplaceTransform . ReplacementKind ) args . ReplaceWith ,
247
- ImputeBySlot = args . ImputeBySlot
248
- } , output ?? input ) ;
224
+ output = NAReplaceTransform . Create ( env , output ?? input , replaceCols . ToArray ( ) ) ;
249
225
250
226
// Concat the NAReplaceTransform output and the NAIndicatorTransform output.
251
227
if ( naIndicatorCols . Count > 0 )
0 commit comments