Browse Source

Update NDArray[object] to be NDArray[numpy.object_] (#5571)

* fix numpy.object_

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
pull/5578/head
Michael Carlstrom 4 months ago committed by GitHub
parent
commit
6412615ebb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      include/pybind11/numpy.h
  2. 7
      tests/test_numpy_array.py

2
include/pybind11/numpy.h

@ -1521,7 +1521,7 @@ struct npy_format_descriptor< @@ -1521,7 +1521,7 @@ struct npy_format_descriptor<
enable_if_t<is_same_ignoring_cvref<T, PyObject *>::value
|| ((std::is_same<T, handle>::value || std::is_same<T, object>::value)
&& sizeof(T) == sizeof(PyObject *))>> {
static constexpr auto name = const_name("object");
static constexpr auto name = const_name("numpy.object_");
static constexpr int value = npy_api::NPY_OBJECT_;

7
tests/test_numpy_array.py

@ -302,6 +302,13 @@ def test_constructors(): @@ -302,6 +302,13 @@ def test_constructors():
assert results["array_t<double>"].dtype == np.float64
def test_array_object_type(doc):
assert (
doc(m.pass_array_object_return_as_list)
== "pass_array_object_return_as_list(arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.object_]) -> list"
)
def test_overload_resolution(msg):
# Exact overload matches:
assert m.overloaded(np.array([1], dtype="float64")) == "double"

Loading…
Cancel
Save