From 211e763ff871732bb4d5e9d8de3a9b3444ad14b3 Mon Sep 17 00:00:00 2001 From: Shaun Patterson Date: Sat, 21 Nov 2026 11:47:59 -0500 Subject: [PATCH] fix(#433): to_java_float_array names the numpy extra when NumPy is missing on the native build --- src/arcadedb/vector.py | 7 +++++++ tests/test_vector.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/arcadedb/vector.py b/src/arcadedb/vector.py index 3c407068..227fd33e 100644 --- a/src/arcadedb/vector.py +++ b/src/arcadedb/vector.py @@ -47,8 +47,15 @@ def to_java_float_array(vector): Returns: Java float array compatible with ArcadeDB vector indexes + + Raises: + ImportError: On the ``arcadedb`` (native) package when NumPy is not installed; the array it returns is a NumPy array. """ if _native_enabled(): + if _np is None: + raise ImportError( + "to_java_float_array() needs NumPy on the arcadedb package: install it with 'uv add \"arcadedb[numpy]\"'" + ) return _np.asarray( vector if hasattr(vector, "__array__") else list(vector), dtype=_np.float32 ) diff --git a/tests/test_vector.py b/tests/test_vector.py index 6f49f272..5f09db94 100644 --- a/tests/test_vector.py +++ b/tests/test_vector.py @@ -59,6 +59,20 @@ def test_to_java_byte_array_accepts_bytes_like_fast_paths(jvm): ) == [0, 127, -1] +def test_to_java_float_array_without_numpy_on_the_native_build_says_what_to_install( + monkeypatch, +): + """NumPy is an optional extra of the ``arcadedb`` package. The native conversion read ``_np.asarray`` unguarded, so a list + raised "'NoneType' object has no attribute 'asarray'" instead of naming the extra. + """ + from arcadedb import vector + + monkeypatch.setattr(vector, "_native_enabled", lambda: True) + monkeypatch.setattr(vector, "_np", None) + with pytest.raises(ImportError, match=r"arcadedb\[numpy\]"): + arcadedb.to_java_float_array([0.1, 0.2]) + + def test_to_java_float_array_accepts_numpy_directly(jvm): """to_java_float_array should accept NumPy arrays without Python-list copies.""" np = pytest.importorskip("numpy")