Skip to content

Commit

Permalink
Fix DataFrame loading doesn't support int16/uint16 types
Browse files Browse the repository at this point in the history
  • Loading branch information
asmirnov82 authored and aloneguid committed Apr 16, 2024
1 parent 3feaac2 commit db69aa5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Parquet.Test/DataAnalysis/DataFrameReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Parquet.Test.DataAnalysis {
public class DataFrameReaderTest : TestBase {

[Theory]
[InlineData(typeof(short), (short)1, (short)2)]
[InlineData(typeof(short?), null, (short)2)]
[InlineData(typeof(int), 1, 2)]
[InlineData(typeof(int?), null, 2)]
[InlineData(typeof(bool), true, false)]
Expand Down
32 changes: 32 additions & 0 deletions src/Parquet/Data/Analysis/DataFrameMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,32 @@ public static void AppendValues(DataFrameColumn dfc, DataColumn dc) {
}
return;
}
if(dc.Field.ClrType == typeof(short)) {
var tdfc = (PrimitiveDataFrameColumn<short>)dfc;
if(dc.Field.ClrType == dc.Field.ClrNullableIfHasNullsType) {
foreach(short el in (short[])dc.Data) {
tdfc.Append(el);
}
} else {
foreach(short? el in (short?[])dc.Data) {
tdfc.Append(el);
}
}
return;
}
if(dc.Field.ClrType == typeof(ushort)) {
var tdfc = (PrimitiveDataFrameColumn<ushort>)dfc;
if(dc.Field.ClrType == dc.Field.ClrNullableIfHasNullsType) {
foreach(ushort el in (ushort[])dc.Data) {
tdfc.Append(el);
}
} else {
foreach(ushort? el in (ushort?[])dc.Data) {
tdfc.Append(el);
}
}
return;
}
if(dc.Field.ClrType == typeof(DateTime)) {
var tdfc = (PrimitiveDataFrameColumn<DateTime>)dfc;
if(dc.Field.ClrType == dc.Field.ClrNullableIfHasNullsType) {
Expand Down Expand Up @@ -313,6 +339,12 @@ public static Array GetTypedDataFast(DataFrameColumn col) {
if(col.DataType == typeof(sbyte)) {
return ((PrimitiveDataFrameColumn<sbyte>)col).ToArray();
}
if(col.DataType == typeof(short)) {
return ((PrimitiveDataFrameColumn<short>)col).ToArray();
}
if(col.DataType == typeof(ushort)) {
return ((PrimitiveDataFrameColumn<ushort>)col).ToArray();
}
if(col.DataType == typeof(DateTime)) {
return ((PrimitiveDataFrameColumn<DateTime>)col).ToArray();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Parquet/Data/Analysis/DataFrameMapper.tt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"ulong",
"byte",
"sbyte",
"short",
"ushort",
"DateTime",
"TimeSpan",
"decimal",
Expand Down

0 comments on commit db69aa5

Please sign in to comment.