Skip to content

Conversation

@cielavenir
Copy link
Contributor

@cielavenir cielavenir commented Jan 7, 2026

Description

AttributeError: `np.longcomplex` was removed in the NumPy 2.0 release. Use `np.clongdouble` instead.

Suggested changelog entry:

  • Fixed docstring for long double complex types to use numpy.clongdouble instead of the deprecated numpy.longcomplex (removed in NumPy 2.0).

@cielavenir cielavenir mentioned this pull request Jan 7, 2026
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below is a Cursor-generated analysis. I didn't double-check the analysis (in my experience such analyses are pretty reliable).


Question

Will this change break numpy v1 compatibility?

Answer

No, this change will NOT break numpy v1 compatibility.

Analysis

The Change

The PR changes the docstring type annotation from numpy.longcomplex to numpy.clongdouble in include/pybind11/numpy.h:

-                                           const_name("numpy.longcomplex"));
+                                           const_name("numpy.clongdouble"));

numpy.clongdouble Availability

numpy.clongdouble has existed in numpy since at least version 1.14.0 (January 2018). Looking at numpy's source code (numpy/core/numerictypes.py), longcomplex was actually just an alias for clongdouble:

('longcomplex', 'clongdouble'),  # alias mapping in numpy

This can be verified in numpy 1.14.0's source:

  • clongdouble is the canonical name
  • longcomplex and clongfloat were aliases pointing to clongdouble

pybind11's Minimum NumPy Requirements

Based on tests/requirements.txt, the oldest numpy versions tested are:

Python Version NumPy Version
CPython 3.8-3.9 ~=1.21.5
CPython 3.10 ~=1.22.2
CPython 3.11-3.12 ~=1.26.0
PyPy 3.8 ~=1.23.0

All of these are well after clongdouble was introduced (1.14.0).

What Happened in NumPy 2.0

In NumPy 2.0, the deprecated alias np.longcomplex was removed, but the canonical name np.clongdouble remains available. The error message that prompted this PR states:

AttributeError: `np.longcomplex` was removed in the NumPy 2.0 release. Use `np.clongdouble` instead.

Conclusion

The PR correctly uses the canonical name numpy.clongdouble which:

  • Has been available since numpy 1.14+ (2018)
  • Works in both NumPy 1.x and NumPy 2.x
  • Is the recommended replacement per NumPy's own guidance

Since pybind11 only tests with numpy ≥1.21.5, this change is perfectly safe and maintains full backward compatibility.

@rwgk
Copy link
Collaborator

rwgk commented Jan 7, 2026

Thanks!

@rwgk rwgk merged commit 745e568 into pybind:master Jan 7, 2026
87 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs changelog Possibly needs a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants