Skip to content

Commit 2aa9bc4

Browse files
Adding DataFrame.Dtypes support (#635)
1 parent 10677de commit 2aa9bc4

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/csharp/Microsoft.Spark.E2ETest/IpcTests/Sql/DataFrameTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Collections.Generic;
67
using System.Linq;
78
using Apache.Arrow;
89
using Microsoft.Data.Analysis;
@@ -459,6 +460,13 @@ public void TestSignaturesV2_3_X()
459460

460461
Assert.Equal(2, _df.Columns().ToArray().Length);
461462

463+
var expected = new List<Tuple<string, string>>
464+
{
465+
new Tuple<string, string>("age", "integer"),
466+
new Tuple<string, string>("name", "string")
467+
};
468+
Assert.Equal(expected, _df.DTypes());
469+
462470
Assert.IsType<bool>(_df.IsLocal());
463471

464472
Assert.IsType<bool>(_df.IsStreaming());

src/csharp/Microsoft.Spark/Sql/DataFrame.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ public void Explain(bool extended = false)
8484
Console.WriteLine((string)execution.Invoke(extended ? "toString" : "simpleString"));
8585
}
8686

87+
/// <summary>
88+
/// Returns all column names and their data types as an IEnumerable of Tuples.
89+
/// </summary>
90+
/// <returns>IEnumerable of Tuple of strings</returns>
91+
public IEnumerable<Tuple<string, string>> DTypes() =>
92+
Schema().Fields.Select(
93+
f => new Tuple<string, string>(f.Name, f.DataType.SimpleString));
94+
8795
/// <summary>
8896
/// Returns all column names.
8997
/// </summary>

0 commit comments

Comments
 (0)