pybind / pybind/pybind11

numpy: Request for user-defined types? (beyond structured dtypes and dtype=object)

Open
#2,259 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

I realized that I didn't create an upstream issue, so I'm placing this here.

Background for NumPy

Basically, NumPy can allow to do custom dtypes through 3 different mechanisms (that I'm aware of):

  1. Structured Types (pybind11 documentation)
  2. dtype=object - see this PR: #1152
  3. User-defined dtypes: See NumPy issue: https://github.com/numpy/numpy/issues/10721 (there may be better docs, but I need to find 'em...)

The focus of this issue supporting (3).

(TODO for myself: Replace above issue links with NumPy / pybind11 docs)

Current State for pybind11

pybind11 itself already supports (1):
https://pybind11.readthedocs.io/en/stable/advanced/pycpp/numpy.html#structured-types

Supporting (2) was done by Robin Deits, we have refined it in our RobotLocomotion/pybind11 fork, and have made an upstream PR to pybind11 in #1152.

Supporting (3) is a bit of a finicky problem, as alluded in https://github.com/numpy/numpy/issues/10721.
Motivated by https://github.com/RobotLocomotion/drake/issues/8116, I made an old prototype / integration branch here: https://github.com/RobotLocomotion/drake/pull/8452

Related pybind11 issues / PRs:

  • #1170
  • #1152 (#647)

I also have not revisited this in about ~1.5 years, may come back around to it.

FTR @eric-wieser has provided some suggestions and workarounds on some of the related threads. I'll admit that I haven't yet had time to process them to a full extent, and will post here once I am able. (Sorry Eric!)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading NumPy issue #10721 and related pybind11 issues #1170 and #1152, then review the referenced Drake integration PR #8452. Establish the supported user-defined dtype scope and acceptance criteria before implementation; this issue names no repository files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, numpy, python
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.