'Filter a Microsoft.Data.Analysis.DataFrame by DateTime?

Using the Microsoft.Data.Analysis package (0.18.0), I'm attempting to create a Filter query for a DateTime column and I'm receiving a System.NotSupportedException exception.

Example code:

DateTime[] birthdays = {DateTime.Parse("4/23/1990"), DateTime.Parse("4/5/1982"), DateTime.Parse("2/1/1980"), DateTime.Parse("9/10/1994") };
var birthdayColumn = new PrimitiveDataFrameColumn<DateTime>("Birthday",birthdays);
var df = new DataFrame(birthdayColumn);
var query = df["Birthday"].ElementwiseEquals(DateTime.Parse("4/5/1982"));
var theBirthday = df.Filter(query);

Exception is thrown on the 4th line:enter image description here

Any ideas? How do I filter a DataFrame by a System.DateTime column?



Solution 1:[1]

I was able to work around this seeming limitation by adding a new Int64 column representing the DateTime column in Ticks, and then filtering on that column:

DateTime[] birthdays = {DateTime.Parse("4/23/1990"), DateTime.Parse("4/5/1982"), DateTime.Parse("2/1/1980"), DateTime.Parse("9/10/1994") };
var birthdayColumn = new PrimitiveDataFrameColumn<DateTime>("Birthday",birthdays);
var df = new DataFrame(birthdayColumn);
var ticks = df["Birthday"].Cast<DateTime>().Select(x => x.Ticks);
df["BirthdayTicks"] = new Int64DataFrameColumn("BirthdayTicks", ticks);
var query = df["BirthdayTicks"].ElementwiseEquals(DateTime.Parse("4/5/1982").Ticks);
var theBirthday = df.Filter(query);

Solution 2:[2]

Filter() only has overloads for Int32, Int64, and Boolean types, not DateTime. The workaround that you used is likely the best option at this time.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 D. Reagan
Solution 2 chrisxfire