Skip to content

DataFrame merge results in column datatype problem #6127

Closed

Description

@olavt

.Net Core 3.1
Microsoft.Data.Analysis Nuget package version: 0.19.1

The last line of the following program crashes with the exception:

System.ArgumentException: 'Cannot cast column holding System.Double values to type System.Double'

using Microsoft.Data.Analysis;
using System;
using System.Linq;

namespace TestDataFRame
{
internal class Program
{
static void Main(string[] args)
{
DateTime?[] dates1 = { new DateTime(2022, 03, 01), new DateTime(2022, 03, 02), new DateTime(2022, 03, 03) };
double?[] closePrices = { 10.5, 12.4, 11.3 };

        DateTime?[] dates2 = { new DateTime(2022, 03, 01), new DateTime(2022, 03, 02), new DateTime(2022, 03, 03) };
        double[] shortPercentages = { 2.34, 2.36, 3.01 };

        DataFrame dataFrame1 = new DataFrame();
        dataFrame1.Columns.Add(new PrimitiveDataFrameColumn<DateTime>("Date", dates1));
        dataFrame1.Columns.Add(new DoubleDataFrameColumn("ClosePrice", closePrices));

        var numbers1 = dataFrame1.Columns.GetDoubleColumn("ClosePrice").ToArray();

        DataFrame dataFrame2 = new DataFrame();
        dataFrame2.Columns.Add(new PrimitiveDataFrameColumn<DateTime>("Date", dates1));
        dataFrame2.Columns.Add(new DoubleDataFrameColumn("ShortPercentage", shortPercentages));

        var numbers2 = dataFrame2.Columns.GetDoubleColumn("ShortPercentage").ToArray();

        DataFrame dataFrame = dataFrame1.Merge<DateTime>(dataFrame2, "Date", "Date", joinAlgorithm: JoinAlgorithm.Left);
        var numbers = dataFrame.Columns.GetDoubleColumn("ClosePrice").ToArray();
    }
}

}

Activity

  1. michaelgsharp commented on Mar 18, 2022

    @michaelgsharp
    Contributor

    Alright, the issue is that merge is calling "Clone" on the columns, but Clone returns slightly different types. For example, Instead of returning DoubleDataFrameColumn it is returning PrimitiveDataFrameColumn<double>. DoubleDataFrameColumn does extend PrimitiveDataFrameColumn<double> but they aren't the same type obviously. The problem then is that in the call to GetDoubleColumn, the check if (column is DoubleDataFrameColumn ret) fails because its not actually a DoubleDataFrameColumn anymore.

    I not sure the exact best way to fix this from a code standpoint. Probably needs a little bit more investigation to figure out the best way. @luisquintanilla for visiblity.

  2. added this to the ML.NET Future milestone on Apr 11, 2022
  3. removed this from the ML.NET Future milestone on Dec 1, 2022
  4. ghost added
    untriagedNew issue has not been triaged
    on Dec 1, 2022
  5. added this to the ML.NET 3.0 milestone on Dec 1, 2022
  6. ghost removed
    untriagedNew issue has not been triaged
    on Dec 1, 2022
  7. ghost added
    in-prA pull request is open to resolve this issue
    on May 14, 2023
  8. ghost removed
    in-prA pull request is open to resolve this issue
    on Jun 13, 2023
  9. ghost locked as resolved and limited conversation to collaborators on Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions