Skip to content

failure to convert numpy.float64 into System.Double #1936

Description

@rzindler

Environment

  • Pythonnet version: 3.0
  • Python version: 3.x
  • Operating System: Windows/Linux
  • .NET Runtime: x

Details

Passing in a numpy array to a C# function that takes a double[] parameter fails.

python code:
test_array = np.array([123, 345], np.float)
CSharpClass.Test(test_array)

C# code
public static void Test(double[] TestData) {...}

I already have a fix for this issue.

In Runtime.cs, change PyFloat_Check(...) to

    internal static bool PyFloat_Check(BorrowedReference ob)
    {
        return PyObject_TypeCheck(ob, PyFloatType);
        //return PyObject_TYPE(ob) == PyFloatType; // existing code
    }

This will convert any type that is derived from PyFloatType, which includes numpy.float64

Activity

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions