Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests for numpy 2.0 #4258

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/4258.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for `bool` conversion with `numpy` 2.0's `numpy.bool` type
1 change: 1 addition & 0 deletions pyo3-macros-backend/src/pyimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ fn impl_py_methods(
) -> TokenStream {
let Ctx { pyo3_path } = ctx;
quote! {
#[allow(unknown_lints, non_local_definitions)]
impl #pyo3_path::impl_::pyclass::PyMethods<#ty>
for #pyo3_path::impl_::pyclass::PyClassImplCollector<#ty>
{
Expand Down
6 changes: 5 additions & 1 deletion pytests/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def test_import_in_subinterpreter_forbidden():
def test_type_full_name_includes_module():
numpy = pytest.importorskip("numpy")

assert pyo3_pytests.misc.get_type_full_name(numpy.bool_(True)) == "numpy.bool_"
# For numpy 1.x and 2.x
assert pyo3_pytests.misc.get_type_full_name(numpy.bool_(True)) in [
"numpy.bool",
"numpy.bool_",
]


def test_accepts_numpy_bool():
Expand Down
2 changes: 1 addition & 1 deletion src/types/boolobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl FromPyObject<'_> for bool {
if obj
.get_type()
.name()
.map_or(false, |name| name == "numpy.bool_")
.map_or(false, |name| name == "numpy.bool_" || name == "numpy.bool")
{
let missing_conversion = |obj: &Bound<'_, PyAny>| {
PyTypeError::new_err(format!(
Expand Down
Loading