5050if TYPE_CHECKING : # pragma: nocover
5151 from ctypes import c_void_p as ScopingPointer
5252
53+ from numpy import typing as np_typing
54+
5355 from ansys .dpf .core .server_types import AnyServerType
5456 import ansys .grpc .dpf .scoping_pb2 .Scoping as ScopingMessage
5557
56- IdVectorType = Union [list [int ], range ]
58+ IdVectorType = Union [list [int ], range , np_typing . NDArray [ np . int32 ] ]
5759
5860
5961class Scoping :
@@ -184,6 +186,9 @@ def _set_location(self, loc=locations.nodal):
184186 def _set_ids (self , ids : IdVectorType ):
185187 """Set the ids.
186188
189+ Scoping IDs are stored as int32.
190+ Converts automatically int64 Numpy arrays to int32.
191+
187192 Parameters
188193 ----------
189194 ids:
@@ -192,6 +197,14 @@ def _set_ids(self, ids: IdVectorType):
192197 """
193198 if isinstance (ids , range ):
194199 ids = list (ids )
200+ if isinstance (ids , np .ndarray ):
201+ if ids .dtype == np .int64 :
202+ ids = ids .astype (np .int32 )
203+ if ids .dtype != np .int32 :
204+ raise ValueError (
205+ f"Accepted dtypes for NumPy arrays when setting scoping IDs are "
206+ f"'np.int32' and np.int64' (provided is '{ ids .dtype } ')."
207+ )
195208 if isinstance (self ._server , server_types .InProcessServer ):
196209 self ._api .scoping_resize (self , len (ids ))
197210 ids_ptr = self ._api .scoping_get_ids (self , len (ids ))
0 commit comments