Skip to content

Conversation

@cjdoris
Copy link
Member

@cjdoris cjdoris commented Jan 22, 2026

Closes #737

Motivation

  • Provide a simple Python-side mapping from primitive Julia TypeValue objects to the corresponding NumPy dtype to aid interoperability (buffers/array conversions).

Description

  • Add a @property __numpy_dtype__ on TypeValue (in src/JlWrap/type.jl) that imports numpy and returns numpy.dtype(...) for the basic Bool, Int*, UInt*, Float*, Complex{Float*} (where supported) and Ptr{Cvoid} types.
  • ComplexF16 (Complex{Float16}) is not mapped because NumPy does not support a complex32 alias here, so it is intentionally left unsupported.
  • Unsupported/unknown Julia types raise AttributeError from __numpy_dtype__.
  • Add pytest coverage in pytest/test_all.py verifying correct dtype mappings and that unsupported types (e.g. ComplexF16, String) raise AttributeError.

Testing

  • Ran julia --project -e 'using Pkg; Pkg.test()', which completed successfully (registry update produced a warning but tests passed).
  • Ran julia --project -e 'using Pkg; Pkg.test(coverage=true)', which completed successfully (registry update warning reported).
  • Ran Python tests with uv run pytest -s --nbval ./pytest; an initial failure surfaced (NumPy does not accept a "complex32" alias), the implementation and tests were adjusted, and the final uv run pytest -s --nbval ./pytest completed with 19 passed.
  • Ran coverage uv run pytest -s --nbval --cov=pysrc ./pytest, which completed successfully and reported the Python-side coverage summary (overall pysrc coverage reported by the run).

Codex Task

@cjdoris cjdoris merged commit f0365a9 into main Jan 23, 2026
@cjdoris cjdoris deleted the codex/add-typevalue.__numpy_dtype__-property branch January 23, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow coercion of Julia types to NumPy dtypes

2 participants