@@ -89,13 +89,28 @@ def cases(
8989 return builder .else_ (else_ ).end ()
9090
9191
92- @overload
93- def bind (t : ibis .Table , ref : Any , / ) -> tuple [ibis .Value , ...]: ...
94- @overload
95- def bind (t : ibis .Deferred , ref : Any , / ) -> tuple [ibis .Deferred ]: ...
92+ IntoValue = str | int | ibis .Deferred | ibis .Value | Callable [[ibis .Table ], ibis .Value ]
9693
9794
98- def bind (t : ibis .Deferred | ibis .Table , ref : Any ) -> tuple [ibis .Value , ...]:
95+ @overload
96+ def bind (
97+ t : ibis .Table ,
98+ ref : IntoValue | Iterable [IntoValue ] | Mapping [str , IntoValue ],
99+ / ,
100+ ) -> tuple [ibis .Value , ...]: ...
101+ @overload
102+ def bind (
103+ t : ibis .Deferred ,
104+ ref : IntoValue | Iterable [IntoValue ] | Mapping [str , IntoValue ],
105+ / ,
106+ ) -> tuple [ibis .Deferred ]: ...
107+
108+
109+ def bind (
110+ t : ibis .Deferred | ibis .Table ,
111+ ref : IntoValue | Iterable [IntoValue ] | Mapping [str , IntoValue ],
112+ / ,
113+ ) -> tuple [ibis .Value , ...]:
99114 """Reference into a table to get Columns and Scalars.
100115
101116 ibis._.bind(ref) does not work because it returns another Deferred.
@@ -110,49 +125,21 @@ def bind(t: ibis.Deferred | ibis.Table, ref: Any) -> tuple[ibis.Value, ...]:
110125
111126
112127@overload
113- def bind_one (t : ibis .Table , ref : Any , / ) -> ibis .Value : ...
128+ def bind_one (t : ibis .Table , ref : IntoValue , / ) -> ibis .Value : ...
114129@overload
115- def bind_one (t : ibis .Deferred , ref : Any , / ) -> ibis .Deferred : ...
130+ def bind_one (t : ibis .Deferred , ref : IntoValue , / ) -> ibis .Deferred : ...
116131
117132
118- def bind_one (t : ibis .Deferred | ibis .Table , ref : Any ) -> ibis .Value | ibis .Deferred :
133+ def bind_one (
134+ t : ibis .Deferred | ibis .Table , ref : IntoValue , /
135+ ) -> ibis .Value | ibis .Deferred :
119136 """Like bind(), but ensure that exactly one value is returned."""
120137 vals = bind (t , ref )
121138 if len (vals ) != 1 :
122139 raise ValueError (f"Expected 1 value, got { len (vals )} from { ref } " )
123140 return vals [0 ]
124141
125142
126- def get_column (
127- t : ir .Table , ref : Any , * , on_many : Literal ["error" , "struct" ] = "error"
128- ) -> ir .Column :
129- """Get a column from a table using some sort of reference to the column.
130-
131- ref can be a string, a Deferred, a callable, an ibis selector, etc.
132-
133- Parameters
134- ----------
135- t :
136- The table
137- ref :
138- The reference to the column
139- on_many :
140- What to do if ref returns multiple columns. If "error", raise an error.
141- If "struct", return a StructColumn containing all the columns.
142- """
143- cols = bind (t , ref )
144- if isinstance (t , ibis .Deferred ):
145- # This is by definition a single column
146- return cols [0 ]
147- if len (cols ) != 1 :
148- if on_many == "error" :
149- raise ValueError (f"Expected 1 column, got { len (cols )} " )
150- if on_many == "struct" :
151- return ibis .struct ({c .get_name (): c for c in cols })
152- raise ValueError (f"on_many must be 'error' or 'struct'. Got { on_many } " )
153- return cols [0 ]
154-
155-
156143def ensure_ibis (
157144 val : Any , type : str | dt .DataType | None = None
158145) -> ir .Value | ibis .Deferred :
0 commit comments