Skip to content

Commit 6708456

Browse files
author
Becca McHenry
authored
Add VBufferDataFrameCoumn to DataFrame (#6409)
* vbuffer file * updates to vbuffer file * vector * edit to single list * update to list * fix tests * cleanup PR * fix all the tests * change vbuffertest * update string * revert csproj string issue * update string namespace * update summary tag
1 parent c55038f commit 6708456

File tree

7 files changed

+560
-5
lines changed

7 files changed

+560
-5
lines changed

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public static DataFrame ToDataFrame(this IDataView dataView, long maxRows, param
116116
{
117117
dataFrameColumns.Add(new StringDataFrameColumn(dataViewColumn.Name));
118118
}
119+
else if (type is VectorDataViewType vectorType)
120+
{
121+
dataFrameColumns.Add(GetVectorDataFrame(vectorType, dataViewColumn.Name));
122+
}
119123
else
120124
{
121125
throw new NotSupportedException(String.Format(Microsoft.Data.Strings.NotSupportedColumnType, type.RawType.Name));
@@ -143,6 +147,66 @@ public static DataFrame ToDataFrame(this IDataView dataView, long maxRows, param
143147

144148
return new DataFrame(dataFrameColumns);
145149
}
150+
151+
private static DataFrameColumn GetVectorDataFrame(VectorDataViewType vectorType, string name)
152+
{
153+
var itemType = vectorType.ItemType;
154+
155+
if (itemType.RawType == typeof(bool))
156+
{
157+
return new VBufferDataFrameColumn<bool>(name);
158+
}
159+
else if (itemType.RawType == typeof(byte))
160+
{
161+
return new VBufferDataFrameColumn<byte>(name);
162+
}
163+
else if (itemType.RawType == typeof(double))
164+
{
165+
return new VBufferDataFrameColumn<double>(name);
166+
}
167+
else if (itemType.RawType == typeof(float))
168+
{
169+
return new VBufferDataFrameColumn<Single>(name);
170+
}
171+
else if (itemType.RawType == typeof(int))
172+
{
173+
return new VBufferDataFrameColumn<Int32>(name);
174+
}
175+
else if (itemType.RawType == typeof(long))
176+
{
177+
return new VBufferDataFrameColumn<Int64>(name);
178+
}
179+
else if (itemType.RawType == typeof(sbyte))
180+
{
181+
return new VBufferDataFrameColumn<sbyte>(name);
182+
}
183+
else if (itemType.RawType == typeof(short))
184+
{
185+
return new VBufferDataFrameColumn<short>(name);
186+
}
187+
else if (itemType.RawType == typeof(uint))
188+
{
189+
return new VBufferDataFrameColumn<uint>(name);
190+
}
191+
else if (itemType.RawType == typeof(ulong))
192+
{
193+
return new VBufferDataFrameColumn<ulong>(name);
194+
}
195+
else if (itemType.RawType == typeof(ushort))
196+
{
197+
return new VBufferDataFrameColumn<ushort>(name);
198+
}
199+
else if (itemType.RawType == typeof(char))
200+
{
201+
return new VBufferDataFrameColumn<char>(name);
202+
}
203+
else if (itemType.RawType == typeof(decimal))
204+
{
205+
return new VBufferDataFrameColumn<decimal>(name);
206+
}
207+
208+
throw new NotSupportedException(String.Format(Microsoft.Data.Strings.VectorSubTypeNotSupported, itemType.ToString()));
209+
}
146210
}
147211

148212
}

src/Microsoft.Data.Analysis/Strings.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.Data.Analysis/Strings.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,8 @@
243243
<data name="StreamDoesntSupportReading" xml:space="preserve">
244244
<value>Stream doesn't support reading</value>
245245
</data>
246+
<data name="VectorSubTypeNotSupported" xml:space="preserve">
247+
<value>Specified vector subtype {0} is not supported.</value>
248+
<comment>{0} vectory subtype</comment>
249+
</data>
246250
</root>

0 commit comments

Comments
 (0)