@@ -224,6 +224,7 @@ def register_function(
224224 name : str ,
225225 parameters : List [Tuple [str , type ]],
226226 return_type : type ,
227+ replace : bool = False ,
227228 ):
228229 """
229230 Register a custom function with the given name.
@@ -267,6 +268,7 @@ def f(x):
267268 parameters (:obj:`List[Tuple[str, type]]`): A list ot tuples of parameter name and parameter type.
268269 Use `numpy dtypes <https://numpy.org/doc/stable/reference/arrays.dtypes.html>`_ if possible.
269270 return_type (:obj:`type`): The return type of the function
271+ replace (:obj:`bool`): Do not raise an error if the function is already present
270272
271273 See also:
272274 :func:`register_aggregation`
@@ -277,7 +279,7 @@ def f(x):
277279 )
278280
279281 name = name .lower ()
280- if name in self .functions :
282+ if not replace and name in self .functions :
281283 if self .functions [name ] != f :
282284 raise ValueError (
283285 "Registering different functions with the same name is not allowed"
@@ -290,6 +292,7 @@ def register_aggregation(
290292 name : str ,
291293 parameters : List [Tuple [str , type ]],
292294 return_type : type ,
295+ replace : bool = False ,
293296 ):
294297 """
295298 Register a custom aggregation with the given name.
@@ -333,6 +336,7 @@ def register_aggregation(
333336 parameters (:obj:`List[Tuple[str, type]]`): A list ot tuples of parameter name and parameter type.
334337 Use `numpy dtypes <https://numpy.org/doc/stable/reference/arrays.dtypes.html>`_ if possible.
335338 return_type (:obj:`type`): The return type of the function
339+ replace (:obj:`bool`): Do not raise an error if the function is already present
336340
337341 See also:
338342 :func:`register_function`
@@ -343,7 +347,7 @@ def register_aggregation(
343347 )
344348
345349 name = name .lower ()
346- if name in self .functions :
350+ if not replace and name in self .functions :
347351 if self .functions [name ] != f :
348352 raise ValueError (
349353 "Registering different functions with the same name is not allowed"
0 commit comments