11import functools
22import inspect
3- import typing
43from typing import Any
54from typing import Callable
65from typing import List
109
1110from . import utils
1211from .dtypes import SQLString
13- from .typing import Masked
1412
1513
1614ParameterType = Union [
@@ -61,27 +59,6 @@ def is_valid_callable(obj: Any) -> bool:
6159 )
6260
6361
64- def verify_mask (obj : Any ) -> bool :
65- """Verify that the object is a tuple of two vector types."""
66- if not typing .get_origin (obj ) is Masked :
67- raise TypeError (
68- f'expected a Masked type, but got { type (obj )} ' ,
69- )
70- return True
71-
72-
73- def verify_masks (obj : Callable [..., Any ]) -> bool :
74- """Verify that the function parameters and return value are all masks."""
75- ann = utils .get_annotations (obj )
76- for name , value in ann .items ():
77- if not verify_mask (value ):
78- raise TypeError (
79- f'Expected a vector type for the parameter { name } '
80- f'in function { obj .__name__ } , but got { value } ' ,
81- )
82- return True
83-
84-
8562def expand_types (args : Any ) -> Optional [Union [List [str ], Type [Any ]]]:
8663 """Expand the types for the function arguments / return values."""
8764 if args is None :
@@ -123,7 +100,6 @@ def _func(
123100 name : Optional [str ] = None ,
124101 args : Optional [ParameterType ] = None ,
125102 returns : Optional [ReturnType ] = None ,
126- with_null_masks : bool = False ,
127103) -> Callable [..., Any ]:
128104 """Generic wrapper for UDF and TVF decorators."""
129105
@@ -132,7 +108,6 @@ def _func(
132108 name = name ,
133109 args = expand_types (args ),
134110 returns = expand_types (returns ),
135- with_null_masks = with_null_masks ,
136111 ).items () if v is not None
137112 }
138113
@@ -141,8 +116,6 @@ def _func(
141116 # in at that time.
142117 if func is None :
143118 def decorate (func : Callable [..., Any ]) -> Callable [..., Any ]:
144- if with_null_masks :
145- verify_masks (func )
146119
147120 def wrapper (* args : Any , ** kwargs : Any ) -> Callable [..., Any ]:
148121 return func (* args , ** kwargs ) # type: ignore
@@ -153,9 +126,6 @@ def wrapper(*args: Any, **kwargs: Any) -> Callable[..., Any]:
153126
154127 return decorate
155128
156- if with_null_masks :
157- verify_masks (func )
158-
159129 def wrapper (* args : Any , ** kwargs : Any ) -> Callable [..., Any ]:
160130 return func (* args , ** kwargs ) # type: ignore
161131
@@ -180,54 +150,7 @@ def udf(
180150 The UDF to apply parameters to
181151 name : str, optional
182152 The name to use for the UDF in the database
183- args : str | Callable | List[str | Callable], optional
184- Specifies the data types of the function arguments. Typically,
185- the function data types are derived from the function parameter
186- annotations. These annotations can be overridden. If the function
187- takes a single type for all parameters, `args` can be set to a
188- SQL string describing all parameters. If the function takes more
189- than one parameter and all of the parameters are being manually
190- defined, a list of SQL strings may be used (one for each parameter).
191- A dictionary of SQL strings may be used to specify a parameter type
192- for a subset of parameters; the keys are the names of the
193- function parameters. Callables may also be used for datatypes. This
194- is primarily for using the functions in the ``dtypes`` module that
195- are associated with SQL types with all default options (e.g., ``dt.FLOAT``).
196- returns : str, optional
197- Specifies the return data type of the function. If not specified,
198- the type annotation from the function is used.
199-
200- Returns
201- -------
202- Callable
203-
204- """
205- return _func (
206- func = func ,
207- name = name ,
208- args = args ,
209- returns = returns ,
210- with_null_masks = False ,
211- )
212-
213-
214- def udf_with_null_masks (
215- func : Optional [Callable [..., Any ]] = None ,
216- * ,
217- name : Optional [str ] = None ,
218- args : Optional [ParameterType ] = None ,
219- returns : Optional [ReturnType ] = None ,
220- ) -> Callable [..., Any ]:
221- """
222- Define a user-defined function (UDF) with null masks.
223-
224- Parameters
225- ----------
226- func : callable, optional
227- The UDF to apply parameters to
228- name : str, optional
229- The name to use for the UDF in the database
230- args : str | Callable | List[str | Callable], optional
153+ args : str | Type | Callable | List[str | Callable], optional
231154 Specifies the data types of the function arguments. Typically,
232155 the function data types are derived from the function parameter
233156 annotations. These annotations can be overridden. If the function
@@ -240,9 +163,10 @@ def udf_with_null_masks(
240163 function parameters. Callables may also be used for datatypes. This
241164 is primarily for using the functions in the ``dtypes`` module that
242165 are associated with SQL types with all default options (e.g., ``dt.FLOAT``).
243- returns : str, optional
244- Specifies the return data type of the function. If not specified,
245- the type annotation from the function is used.
166+ returns : str | Type | Callable | List[str | Callable] | Table, optional
167+ Specifies the return data type of the function. This parameter
168+ works the same way as `args`. If the function is a table-valued
169+ function, the return type should be a `Table` object.
246170
247171 Returns
248172 -------
@@ -254,5 +178,4 @@ def udf_with_null_masks(
254178 name = name ,
255179 args = args ,
256180 returns = returns ,
257- with_null_masks = True ,
258181 )
0 commit comments