FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Decoder for primitive types in ctypes module · Issue #1276 · pythonnet/pythonnet · GitHub

Repository navigation

Decoder for primitive types in ctypes module #1276

Open

Description

ctypes is a standard Python module for interacting with fixed size integers. Would be nice to provide C# <-> Python conversions for types in that module.

Relevant: https://stackoverflow.com/questions/63801150/how-do-i-pass-a-ulong-type-argument-to-a-c-sharp-function-from-python

Activity

  1. fractus commented on Jul 29, 2022

    Contributor

    A realted topic is numpy and pandas types (any instance of np.ndarray, and pd.core.arrays.ExtensionArray. I tried the following but it didn't work - it's not even triggered, I guess because it's primitives?

        public class NumpyDecoder : IPyObjectDecoder
        {
            public bool CanDecode(PyType objectType, Type targetType)
            {
                return targetType == typeof(double) && objectType.Name.StartsWith("numpy.float64");
            }
    
            public bool TryDecode<T>(PyObject pyObj, out T value)
            {
                value = (T)(object)pyObj.GetAttr("item").As<double>();
                return true;
            }
        }
    Python.Runtime.PyObjectConversions.RegisterDecoder(NumpyDecoder())
    xs = np.array([1.0, 2.0], dtype=np.float64)
    lst = List[Double]()
    lst.Add(xs[0])        # Fails
    lst.Add(xs[0].item()) # Works

    This is also reported in #1887

    See also https://stackoverflow.com/questions/9452775/converting-numpy-dtypes-to-native-python-types

  2. self-assigned this
    on Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL