Skip to content

fix: return numpy arrays from CrystVector/CrystMatrix bindings - #128

Merged
sbillinge merged 2 commits into
diffpy:nanobind_migration_testfrom
clemisch:127_getlatticepar-converter
Nov 14, 2026
Merged

sbillinge merged 2 commits into
diffpy:nanobind_migration_testfrom
clemisch:127_getlatticepar-converter

Conversation

@clemisch

Copy link
Copy Markdown
Contributor

nanobind has no global converter for CrystVector_REAL/CrystMatrix_REAL, so bindings that returned them directly raised when called.

Wrap them in crystvec_to_array/crystmat_to_array:

  • UnitCell.GetLatticePar(), UnitCell.GetOrthonormalCoords()
  • Crystal.GetMinDistanceTable()
  • ScatteringPower.GetScatteringFactor(), GetTemperatureFactor(), GetResonantScattFactReal(), GetResonantScattFactImag(), (both in the base binding and in the forwarding for ScatteringPowerAtom and GlobalScatteringPower)

Add tests that call each method, plus a check that no binding's signature still returns a raw CrystVector/CrystMatrix.

fixes #127

nanobind has no global converter for CrystVector_REAL/CrystMatrix_REAL,
so bindings that returned them directly raised when called.

Wrap them in crystvec_to_array/crystmat_to_array:

- UnitCell.GetLatticePar(), UnitCell.GetOrthonormalCoords()
- Crystal.GetMinDistanceTable()
- ScatteringPower.GetScatteringFactor(), GetTemperatureFactor(),
  GetResonantScattFactReal(), GetResonantScattFactImag(),
  (both in the base binding and in the forwarding for ScatteringPowerAtom
  and GlobalScatteringPower)

Add tests that call each method, plus a check that no binding's
signature still returns a raw CrystVector/CrystMatrix.

fixes diffpy#127
@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.36842% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (nanobind_migration_test@3452813). Learn more about missing BASE report.

Files with missing lines Patch % Lines
tests/test_array_returns.py 97.36% 2 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                     @@
##             nanobind_migration_test     #128   +/-   ##
==========================================================
  Coverage                           ?   98.78%           
==========================================================
  Files                              ?       22           
  Lines                              ?     2312           
  Branches                           ?        0           
==========================================================
  Hits                               ?     2284           
  Misses                             ?       28           
  Partials                           ?        0           
Files with missing lines Coverage Δ
tests/test_array_returns.py 97.36% <97.36%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sbillinge
sbillinge merged commit c2df30c into diffpy:nanobind_migration_test Nov 14, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants