pythonnet / pythonnet/pythonnet
Allow decoders to decode Python types derived from primitives
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 780
- PR merge metrics
- No merged PRs in 30d
Description
Environment
- Pythonnet version: 3.0.2
- Python version: not relevant for this issue
- Operating System: not relevant for this issue
- .NET Runtime: not relevant for this issue
Details
-
We have used the preview version in the past and wrapped it so that we are able to update the package and change against interfaces for future releases. One part of it is converting numpy types. By default such types are not supported anymore in the release version and it seems to be recommended to use codecs instead. I registered a codec (same as pandanet) but
PyObject.As<double>()does not convertPyType = <class 'numpy.int32'>with the help of the codec.
By debugging it never hits the PyObjectConversions.TryDecode because double it is not equal to "object type" and not one of the "DecodableByUserTypes".TODO
to reproduce:
import numpy as np
numpyArray = np.array([1, 2])
// C# part
var value = numpyArray.GetItem(i)
var valueAsT = value.As<double>(); // fails
Whish:
- solution to handle such a case i.e. by configuring hooks or use the existing codec approach to convert before it hits the usual
ToPrimitive(...)function which fails.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at PyObject.As() and trace the path through PyObjectConversions.TryDecode, registered codecs, and ToPrimitive(...), using the numpy.int32 reproduction as the first check. Determine where derived Python primitive types should be accepted and define completion as successful conversion of the shown array values to double without breaking existing codec behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, numpy, python
- Domain
- backend, devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100